Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex weird behaviour
#1
Photo 
Hi,
I'm experimenting a quite weird behaviour of this very simple regex:
Macro Macro40
Code:
Copy      Help
out
;str r = "433\.[^4567]1"
str r = "433\.[012389]1"
str c = "433.21"
str t
ARRAY(str) ris
if(findrx(c r 0 2 t)>=0)
,out t
else
,out "no match"

it SHOULD give a match but it doesn't:
[Image: regex-No-Match.png]

But if I change the character class negating the opposite of the ones I want to match, it works:
Macro Macro40
Code:
Copy      Help
out
str r = "433\.[^4567]1"
;str r = "433\.[012389]1"
str c = "433.21"
str t
ARRAY(str) ris
if(findrx(c r 0 2 t)>=0)
,out t
else
,out "no match"

[Image: regex-Does-Match.png]

If I test the regex on https://regex101.com (PCRE engine) it works, and so it does in RegexBuddy.
Negating the opposite could be a workaround, but is there a way to make character class working as expected?
Am I doing things wrong?

many thanks
#2
[number] is a QM string escape sequence. In this case need to escape [ character. If don't know how to do it: enter the text in the Text dialog and click OK. It inserts code with escaped string.

Macro Macro3163
Code:
Copy      Help
str r = "433\.[91]012389]1"

Another way - raw multiline string.

Macro Macro3163
Code:
Copy      Help
str r =
;433\.[012389]1
#3
Thank you a ton, Gintaras,
a new bit of knowledge learned today!

You support is always GREAT!


Forum Jump:


Users browsing this thread: 1 Guest(s)