Strange character returned with regex.

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

Moderator: General Moderators

Post Reply
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Strange character returned with regex.

Post by social_experiment »

My regular expression looks for this specific value inside an html document:

Code: Select all

$pattern = '/<span id="temp">.+<\/span>/';
// returns 16°C.
Html to find

Code: Select all

<span id="temp">16°C</span>
It returns something else though : 16°C.

I've tried using another pattern (+\d°C) but this doesn't return anything. Is there something that i am missing in terms of the original regular expression?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Strange character returned with regex.

Post by Weirdan »

are you sure your output encoding matches the encoding of the string you're running your regexp on? If it's utf-8 you might have better luck specifying your regexp as utf (/<span id="temp">.+<\/span>/u)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Strange character returned with regex.

Post by social_experiment »

Thanks for the help, the problem was that the charset wasn't specified on the page displaying the information.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply