Page 1 of 1

Bug in RegEx?

Posted: Fri Sep 27, 2019 8:35 pm
by Zimon
Hello,

I have th following code:

Code: Select all

RegEx.s = "(?<=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
CreateRegularExpression(0, RegEx.s)
RegExResult.s = ReplaceRegularExpression(0, "192.178.168.51;PC;User", "---")
Debug RegExResult.s
Can't figure out why PB takes exception to this... isn't this pretty standard RegEx? This is my error msg:

Code: Select all

[ERROR] The specified #RegularExpression is not initialised.
I am running v5.62. Any ideas?

Thanks!

Re: Bug in RegEx?

Posted: Fri Sep 27, 2019 8:51 pm
by STARGÅTE
You can use:RegularExpressionError()
lookbehind assertion is not fixed length

Re: Bug in RegEx?

Posted: Fri Sep 27, 2019 8:57 pm
by Zimon
Thanks! However, I am still clueless as to what the error message is supposed to mean...

Re: Bug in RegEx?

Posted: Fri Sep 27, 2019 9:11 pm
by STARGÅTE
If you use a lookbehind assertion, you can not use non-fixed length strings, like \d{1,3} or .+ or .*.
You have you search it as a group, for example:

Code: Select all

RegEx.s = "(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3};).+"
CreateRegularExpression(0, RegEx.s)
If ExamineRegularExpression(0, "192.178.168.51;PC;User")
	While NextRegularExpressionMatch(0)
		RegExResult.s = RegularExpressionGroup(0, 1) + "---"
		Debug RegExResult
	Wend
EndIf

Re: Bug in RegEx?

Posted: Fri Sep 27, 2019 9:14 pm
by Zimon
Excellent! Thank you for the explanation!