Reputation: 9
I want to program an alert system by checking if several lists of keywords are present in one address.
This is my two variables in PHP :
$MyAdress = "210, street Cardinal Avenue, Canada"; (to testing)
$SearchAdress = "210 Cardinal Avenue"; (from my list of possible keywords to find)
I want to test if my SearchAddress is present in my address and check if words are in the good position, how is it possible ?
With Regex ? (It's always been gobbledegook to me)
By example "210 Cardinal Avenue" return TRUE but "210 Avenue Cardinal" must to return FALSE.
This code PHP check if two keywords occur in String is interesting, but the order is not respected.
Also I resolved problem to transform text in lower and replace foreign characters in a String.
Upvotes: 0
Views: 48
Reputation: 18490
Just wrap the words into \b
word boundaries and concatenate them with .+?
(?i)\b210\b.+?\bcardinal\b.+?\bavenue\b
See this demo at regex101 or a PHP demo at tio.run (used i
flag for ignorecase)
This would match the words in sequence with one or more of any characters in between.
To also match 210CardinalAvenue
drop word boundaries between and use .*?
(demo).
Upvotes: 1