Re: Positive lookahead assertion




tobiah wrote:
(?=...)
Positive lookahead assertion. This succeeds if the contained
regular expression, represented here by ..., successfully
matches at the current location, and fails otherwise.
But, once the contained expression has been tried, the
matching engine doesn't advance at all; the rest of the
pattern is tried right where the assertion started.

I am unable to wrap my mind around this sentence. Could
someone give me an example of how this works, and why
it would be useful?

Thanks,

Toby

--
Posted via a free Usenet account from http://www.teranews.com
Its all about context. If you want to match something but only if it
precedes something else, then you follow the regular expression for
'something' by the regular expression for 'something else' where
`something else` is enclosed by (?=...)

The regular expression engine will surreptitiously check that
'something else' does indeed follow, before returning any match of
'something'.

Unfortunatley the above may be just as hard to decipher as the original
;-)

- Paddy.

.



Relevant Pages

  • Re: Positive lookahead assertion
    ... Positive lookahead assertion. ... regular expression, represented here by ..., successfully ... the rest of the pattern is ... The regular expression engine will surreptitiously check that ...
    (comp.lang.python)
  • Re: Is there a maximum length of a regular expression in python?
    ... internal error in regular expression engine ... this causes the regex compiler to blow up. ... Does no one care about an internal error in the regular expression ...
    (comp.lang.python)
  • Re: regular expression
    ... that fails at least two ways: ... The regular expression ' c*t ' matches both the leading ... If the string to be matched against ... such as 'cat cart' ...
    (comp.soft-sys.matlab)
  • Re: xsd regular expression query
    ... quotes but not both in the same string so you can have: ... If you don't have a convenient regular expression engine locally you ...
    (comp.text.xml)
  • Re: Looking for menu enhancement
    ... Here is a screenshot of a regular expression ... tool that lets the user construct and execute regular expressions ... or needs the facilities of a particular regular expression engine, ... confused by being asked to choose among several dozen alternatives. ...
    (comp.lang.tcl)