Bug in RegEx?

Just starting out? Need help? Post your questions and find answers here.
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Bug in RegEx?

Post 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!
User avatar
STARGÅTE
Addict
Addict
Posts: 2254
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Bug in RegEx?

Post by STARGÅTE »

You can use:RegularExpressionError()
lookbehind assertion is not fixed length
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: Bug in RegEx?

Post by Zimon »

Thanks! However, I am still clueless as to what the error message is supposed to mean...
User avatar
STARGÅTE
Addict
Addict
Posts: 2254
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Bug in RegEx?

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: Bug in RegEx?

Post by Zimon »

Excellent! Thank you for the explanation!
Post Reply