Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi to everybody, I have to verif 1

Status
Not open for further replies.

maxbld

Programmer
Nov 30, 2001
8
IT
Hi to everybody,

I have to verify if a query result contains an intere word or a part of it, to discriminate whether or not to consider it valid. The algorithm core is represented by the following command:

preg_match_all("/([a-z]|[A-Z]|)".$topic."([a-z]|[A-Z]|)/i", $result[$j], $content1);

(This is a php function, but as far as I know you perl guys are the RegExp Wizards)

As you can see it verifies if there are alfabetic characters immediatly around my topic. It does its job pretty well but when $topic contains an accented character. I.e. $topic = "probléme" won't match a string within which there is probléme, due to that 'é'. Nevertheless if it was $topic = "probleme" it would have matched probleme into a string containing it.

It really puzzles me. Does somebody know an explanation to this behavior?

Thank you in advance for any help.

Max.
 
post the code of: preg_match_all() -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Well, I don't know much about PHP, but your regex doesn't make sense. You check for [a-z]|[A-Z] but then tell it to ignore case. Also, you have an or (|) with nothing following it. You could simplify your regex to this:
Code:
preg_match_all("/[a-z]".$topic."[a-z]/i", $result[$j], $content1);

I doubt that will do anything about your accent chars though. It sounds like a problem within "preg_match_all".
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Oops! preg_match_all did *exactly* what it was meant to do. It was me who wasn't aware of the data that were to be matched: $result[$j] contained 'problèmes' instead of 'probléme'.

I beg your pardon for misposting... I was a little confused with my brain overheating. :)

Max.

P.S.
preg_match_all is a php built in function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top