I've trouble about matching ASCII codes in regex in my bash script.
My payload is : payload='#1243669, start 2018-12-17 16:32:50 CET'
My old regex is : regold='(#[^,]+),'
My new regex is : regnew='(#[^\x2c]+)\x2c'
When I do the test in shell, it confirms that new regex doesn't work, whereas it works on regex101.com :
root@test# payload='#1243669, start 2018-12-17 16:32:50 CET'
root@test# regold='(#[^,]+),'
root@test# regnew='(#[^\x2c]+)\x2c'
root@test# if [[ $payload =~ $regold ]]; then echo yes; fi
yes
root@test# if [[ $payload =~ $regnew ]]; then echo yes; fi
Edit:
Question partially answered by telling bash doesn't support PCRE expressions. So I move my regex to this one :
root@test# regex=$'(\x23[^\x2c]+)\x2c[[:space:]]start[[:space:]][[:digit:]]{4}\x2d[[:digit:]]{2}\x2d[[:digit:]]{2}[[:space:]]([^[:space:]]+)[[:space:]][^\x2c]+\x2c[^\x2c]+\x2c[[:space:]](captureme)'
root@test# pattern='Message #1243669, start 2018-12-17 16:32:50 CET, duration 20, captureme'
Again, my expression works great on regex101, sample here https://regex101.com/r/g4UsUN/1
Expression works to this point : ... [[:space:]][^\x2c]+ ... but bash had some difficulties when I add the \x2c
What's going on ?