question about regular expression 
Author Message
 question about regular expression

i got a question about regular expression of VBScript
when I read document about regular expression in next URL

http://www.*-*-*.com/

I find positive and negative lookahead search and I didn't see this in
grep
(well i'm a newbie in windows programming :) )
negative lookahead search is so sensitive but I can't understand
positive lookahead search because I think it's just same with normal
search

in above URL (?=pattern) explains
------------------------------------------------------------------------------
Positive lookahead matches the search string at any point where a
string       matching pattern begins. This is a non-capturing match,
that is, the match is not captured for possible later use. For example
'Windows (?=95|98|NT|2000)' matches "Windows" in "Windows 2000" but
not "Windows" in "Windows 3.1". Lookaheads do not consume characters,
that is, after a match occurs, the search for the next match begins
immediately following the last match, not after the characters that
comprised the lookahead.
-------------------------------------------------------------------------------

But I can't find difference between normal search and positive
lookahead search
for example there's sentences like "windows98 is here" and
"windows2000 is there"
then normal search windows(98|2000) will match both sentences
and positive lookahead search windows(?=98|2000) also match both
sentences
Well, I think I'm misunderstanding the meaning of positive lookahead
search :)
plz show me some example or explanation

have a nice day :)



Mon, 28 Nov 2005 12:45:21 GMT  
 question about regular expression

Quote:

> i got a question about regular expression of vbscript
> when I read document about regular expression in next URL

> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/scri...

> I find positive and negative lookahead search and I didn't see this in
> grep
> (well i'm a newbie in windows programming :) )
> negative lookahead search is so sensitive but I can't understand
> positive lookahead search because I think it's just same with normal
> search

> in above URL (?=pattern) explains
> ------------------------------------------------------------------------------
> Positive lookahead matches the search string at any point where a
> string       matching pattern begins. This is a non-capturing match,
> that is, the match is not captured for possible later use. For example
> 'Windows (?=95|98|NT|2000)' matches "Windows" in "Windows 2000" but
> not "Windows" in "Windows 3.1". Lookaheads do not consume characters,
> that is, after a match occurs, the search for the next match begins
> immediately following the last match, not after the characters that
> comprised the lookahead.
> -------------------------------------------------------------------------------

> But I can't find difference between normal search and positive
> lookahead search
> for example there's sentences like "windows98 is here" and
> "windows2000 is there"
> then normal search windows(98|2000) will match both sentences
> and positive lookahead search windows(?=98|2000) also match both
> sentences

However, to use your two sentences, only the first pattern below will match:
windows(98|2000) is here
windows(?=98|2000) is here

The second pattern can not match anything.

Csaba

- Show quoted text -

Quote:
> Well, I think I'm misunderstanding the meaning of positive lookahead
> search :)
> plz show me some example or explanation

> have a nice day :)



Mon, 28 Nov 2005 14:32:12 GMT  
 question about regular expression

Quote:

> But I can't find difference between normal search and positive
> lookahead search
> for example there's sentences like "windows98 is here" and
> "windows2000 is there"
> then normal search windows(98|2000) will match both sentences
> and positive lookahead search windows(?=98|2000) also match both
> sentences
> Well, I think I'm misunderstanding the meaning of positive lookahead
> search :)
> plz show me some example or explanation

The difference is what gets matched. Positive (and negative) lookaheads are not
part of the match.

win98 = "windows98 is here"
win2k = "windows2000 is there"

with new regexp

  'match the string "windows98" or "windows2000"
  .pattern = "windows(98|2000)"
  wscript.echo .execute(win98)(0)    ' windows98
  wscript.echo .execute(win2k)(0)    ' windows2000

  'match the string "windows", but only if it's followed by "98" or "2000"
  .pattern = "windows(?=98|2000)"
  wscript.echo .execute(win98)(0)    ' windows
  wscript.echo .execute(win2k)(0)    ' windows

end with

--
Steve

Washing one's hands of the conflict between the powerful and the powerless
means to side with the powerful, not to be neutral. -Paulo Freire



Mon, 28 Nov 2005 19:07:20 GMT  
 question about regular expression
thanks for reply
i got it :)
Quote:


> > But I can't find difference between normal search and positive
> > lookahead search
> > for example there's sentences like "windows98 is here" and
> > "windows2000 is there"
> > then normal search windows(98|2000) will match both sentences
> > and positive lookahead search windows(?=98|2000) also match both
> > sentences
> > Well, I think I'm misunderstanding the meaning of positive lookahead
> > search :)
> > plz show me some example or explanation

> The difference is what gets matched. Positive (and negative) lookaheads are not
> part of the match.

> win98 = "windows98 is here"
> win2k = "windows2000 is there"

> with new regexp

>   'match the string "windows98" or "windows2000"
>   .pattern = "windows(98|2000)"
>   wscript.echo .execute(win98)(0)    ' windows98
>   wscript.echo .execute(win2k)(0)    ' windows2000

>   'match the string "windows", but only if it's followed by "98" or "2000"
>   .pattern = "windows(?=98|2000)"
>   wscript.echo .execute(win98)(0)    ' windows
>   wscript.echo .execute(win2k)(0)    ' windows

> end with



Wed, 30 Nov 2005 10:29:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help, really simple question w/ Regular Expressions

2. Really Simple Question on Regular Expressions

3. Question about regular expressions

4. A few questions about Regular Expressions

5. Regular Expression replace question

6. Regular Expression Question

7. Regular Expression Replace Question

8. Regular expression question

9. Regular Expression question

10. Regular Expressions Newbie Question

11. Regular expressions question

12. Regular Expression replace question

 

 
Powered by phpBB® Forum Software