Negative lookahead

Negative lookahead can be used to see if the next element would match a certain pattern. It's often used to prevent a greedy construct from matching a special sequence. For example when matching a quoted string everything should be ignored except for the closing double quote. Using negative lookahead we could do something like this:

Search "\"" {~"\"" .} "\""
Which means:

Ignored Character Set

In this case we could also have used an ignored character set instead of a negative lookahead, i.e. replace {~ "\" " .} with {'~"'} So we get
Search "\"" {'~"'} "\""

The ignored character set { ' ~ " '} wil match anything other than a double quote. (I have added spaces to that expression to reduce confusion as Netsurf won't do character-spacing)

You may like to try this on the sample text - you should find four such quoted strings.

Was this page helpful? Please email me and/or rate this page:


If you want a reply make sure any email address @torrens.org will not get spam-binned!
Optional comment

Other relevant pages

Top of page


Page Information

http://css.torrens.org/valid-html401-bluehttp://css.torrens.org/valid-css Document URI: http://stronged.torrens.org/man/search/examples/negahead.html
Page first published
Last modified:Wed, 06 Mar 2019 19:14:36 GMT
© 2017 - 2024 Richard Torrens.