Page 1 of 1
Does it work?
Posted: Thu Nov 02, 2006 1:58 pm
by visonardo
i want to keep an ocurrence but here must be not ones determinated datas. for example, if i wanna capture a word that must be not following by
magazine word it would be thus
Code: Select all
preg_match_all("word\s*(?!magazine)",$source,$matchs);
but if its not a specific word? but yes i have the conditions of determinated word.
Code: Select all
$condition="regex code here";
preg_match_all("word\s*(?!".$condition.")",$source,$matchs);
can i do it and work?
Posted: Thu Nov 02, 2006 2:36 pm
by feyd
Have you tried it?
Posted: Thu Nov 02, 2006 2:42 pm
by visonardo
this
Code: Select all
preg_match_all("((7\d)|(a\W))",$a,$matchs);
should be the same that
Code: Select all
preg_match_all("((7\d)|(a(?!\w)))",$a,$matchs);
but the last didnt work
how you would do (?!regex_code_here)?
Posted: Thu Nov 02, 2006 3:05 pm
by feyd
Why would it be the same? The first is using basic patterns and metacharacters. The second is using a negative forward assertion. Quite different.
Posted: Thu Nov 02, 2006 6:17 pm
by visonardo
feyd wrote:Why would it be the same? The first is using basic patterns and metacharacters. The second is using a negative forward assertion. Quite different.
the result is the same to
(?!a) than [^a] ----> Do im mistaken?
but would like that be thus to
(?!\w) than [^\w] and than \W but i guess that not.
Does someone tried that?
Posted: Thu Nov 02, 2006 7:10 pm
by feyd
visonardo wrote:Does someone tried that?
Why can't you try it?
Negative lookahead versus negated character class
Posted: Sat Nov 04, 2006 2:08 pm
by GeertDD
visonardo wrote:the result is the same to
(?!a) than [^a] ----> Do im mistaken?
A negative lookahead is not exactly the same as a negated character class. The main difference (as far as I know) is that
a negated character class still needs to match a character, a character not listed in the class. A
negative lookahead doesn't match (or 'consume') a character -- it only
matches a position in the string.
Re: Negative lookahead versus negated character class
Posted: Sat Nov 04, 2006 2:17 pm
by Chris Corbyn
GeertDD wrote:visonardo wrote:the result is the same to
(?!a) than [^a] ----> Do im mistaken?
A negative lookahead is not exactly the same as a negated character class. The main difference (as far as I know) is that
a negated character class still needs to match a character, a character not listed in the class. A
negative lookahead doesn't match (or 'consume') a character -- it only
matches a position in the string.
Correct

Lookaheads and lookbehinds are not actually consuming characters, they are just looking for the presence of them.