Character Classes

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

Moderator: General Moderators

Post Reply
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

Character Classes

Post by nwp »

[abc] matches a, b or c so
[home] matches h, o, m OR e
But I wanna match the compleate word "home"
How can I do it ??
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

/home/ matches "home"

Please do read documentation I linked to in the other thread.
http://www.php.net/manual/en/reference. ... syntax.php
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

Post by nwp »

Ya I've read that I actually need something like this
(\d+?)([^home|^House]+?)(\d+?)
e.g. Match -> 58hello98 not 45house85 not 15home45
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Code: Select all

$s = array("58hello98", "45house85", "15home45", "77blah88");
$r = "/(\d+)(?!house|home)\D+(\d+)/";

print_r(
	preg_grep($r, $s)
);
have a read about lookaheads there.
Post Reply