Jump to content

Regex - negative Lookbehind


Recommended Posts

Hi,

following problem:

I want to check a string of occurence of a word (i.e. appel).

condition:

Is the word inside a quoted string (with ' or ") shouldn't match.

Before match, but also before quoted string, can be written other chars.

Match for the word (insensitiv): "(?i)appel"

Now negativ Lookbehind (because quotes): "(?<!['\x22])(?i)appel"

It works fine.

appel are found in: xyz 123 Appel

not found in: 'Appel xyz OR xyz 'Appel ==> BUT

also found in: ' Appel xyz

Thats why:

No qoutes AND (optional) no other chars behind opening quotes.

OK, now i use following pattern:

"(?<!(['\x22](.+?)|['\x22]))(?i)appel"

With external programm (RegexBuddy) it works, but no match with AutoIt.

I've also tested:

"(?<!(('|\x22)(.+?)|('|\x22)))(?i)appel"

and it's also fails only in AutoIt.

Any Ideas?

Global $s[4] = ["xyz 123 Appel","'Appel xyz","  Appel xyz",'xyz " Appel']
For $i = 0 To UBound($s) -1
    ConsoleWrite($s[$i] & ' = ' & @TAB & StringRegExp($s[$i], "(?<!(['\x22](.+?)|['\x22]))(?i)appel") & @CRLF)
Next
Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

Hi.

Have a look at the syntax description for PCRE if you can see what's giving the trouble you face.

If I understood the help file correctly, PCRE the "RegEx-Engine" used by autoit.

A link to that URL is provided in the help file, topic "StringRegExp", just above the table, the paragraph "Complete description can be found here"

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...