Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex doesn't work: my error or bug?
#1
Hi Gintaras,
this regex (PCRE flavour) finds the substring between two single quotes:
Code:
Select All      Help
(?<=')(.*?)(?=')

It works well when tested in RegexBuddy 4, 
[Image: htdvd4.png]
in https://regexr.com and https://www.regexpal.com:

[Image: 2uglztg.png] [Image: 9jls1h.png]

but if fails in QM:

Code:
Select All      Help
str userNamePattern username risultato
username="WHERE nomepass = 'testname'"
userNamePattern = "(?<=')(.*?)(?=')"
if(findrx(username userNamePattern 0 0 risultato 2)>=0)
    out risultato
else
    mes "match for ''(?<=')(.*?)(?=')'' not found" "Error"

[Image: j5i0wl.png]

is it my fault?

Again thank you for your exceptional support.
#2
It seems it is a bug or feature in the (older) library PCRE version that QM uses. I tested with current PCRE version and it works well.
Workaround 1: use + instead of *
Workaround 2: don't use (?<=')

Also, in you code the submatch argument is 2. Must be 0 or 1.

Macro Macro2980
Code:
Select All      Help
str userNamePattern username risultato
username="= 'testname'"
userNamePattern = "'(.*?)'"
int i=findrx(username userNamePattern 0 0 risultato 1)
out i
out risultato
#3
Ok, i got it.

Thanks again


Forum Jump:


Users browsing this thread: 1 Guest(s)