regex and hex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

regex and hex

Post by jazz090 »

i dont know how to specify 0xE2 0x80 0x98 (single left quote) in regex, i have tried:

Code: Select all

/\xE2\x80\x98/
but no luck so far.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: regex and hex

Post by prometheuzz »

jazz090 wrote:i dont know how to specify 0xE2 0x80 0x98 (single left quote) in regex, i have tried:

Code: Select all

/\xE2\x80\x98/
but no luck so far.
Works like a charm:

Code: Select all

if(preg_match('/\xE2\x80\x98/', '‘')) {
  echo "YES";
} else {
  echo "nope";
}
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: regex and hex

Post by jazz090 »

yes but that will match (‘) in a string, not (‘). note that those are not 3 seperate hexs, they are ONE hex
i want this basicly but (left quote marked as hex)

Code: Select all

if(preg_match('/‘/', $subject)) {
echo "YES";
}else {
echo "nope";
}
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: regex and hex

Post by prometheuzz »

jazz090 wrote:yes but that will match (‘) in a string, not (‘). note that those are not 3 seperate hexs, they are ONE hex
i want this basicly but (left quote marked as hex)

Code: Select all

if(preg_match('/‘/', $subject)) {
echo "YES";
}else {
echo "nope";
}
You may want to try and add the unicode flag after your regex: '/.../u'
Anyway, the quotes all look the same in my browser, but I guess you're still hacking your way through this SQL escaping stuff: can't help you there.

Best of luck.
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: regex and hex

Post by jazz090 »

ahhhhhhh, the browser encoding was set to western europian instead of UTF8, its solved!
Post Reply