Code: Select all
preg_match('|[^-]+|', $whatever)Code: Select all
preg_match('|[^\-]+|', $whatever)Thanks,
Drew
Moderator: General Moderators
Code: Select all
preg_match('|[^-]+|', $whatever)Code: Select all
preg_match('|[^\-]+|', $whatever)Hi Drew,oboedrew wrote:Which of these would be the preferable way to check that a variable contains at least one character that is not a hyphen?
orCode: Select all
preg_match('|[^-]+|', $whatever)
According to http://www.regular-expressions.info/reference.html, a hyphen should be escaped by a backslash unless the hyphen occurs immediately after a caret. But when I try the two versions in a php script, they both seem to work. Are they interchangeable, or am I missing something?Code: Select all
preg_match('|[^\-]+|', $whatever)
Thanks,
Drew
Code: Select all
'/[*]/'
// equals
'/[\*]/'
// equals
'/\*/'