Speed up processing a certain string

Just starting out? Need help? Post your questions and find answers here.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Speed up processing a certain string

Post by NicTheQuick »

If you compile one regular expression at the beginning all the matches should be quite fast. I did not make a speed test, but I can give you a short example I just crafted. Feel free to fix any matching errors because I do not know the correct syntax.
And if you want to try out some regular expressions try this tool and switch to the Python language: https://regex101.com/

Code: Select all

DataSection
	cad:
		Data.s "D1 SOD523 285 705 0 DX.410052E 0 0"
		Data.s "*     some comment"
		Data.s ~"  D1\t\tS0D521    285 705\t 0 DX.410125E\t0        0"
		Data.s ""
EndDataSection

regex = CreateRegularExpression(#PB_Any, "^\s*([^*]+?\b)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9a-zA-Z.]+)\s+(\d+)\s+(\d+)\s*$")

Define line.s
Restore cad
Repeat
	Read.s line
	Debug "--------------------------------"
	Debug line
	If line = ""
		Break
	EndIf

	If ExamineRegularExpression(regex, line)
		If NextRegularExpressionMatch(regex)
			For i = 1 To 8
				Debug "    " + i + ": '" + RegularExpressionGroup(regex, i) + "'"
			Next
		Else
			Debug "    Comment or wrong syntax"
		EndIf
	Else
		Debug "    Error"
    EndIf
ForEver
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply