Page 2 of 2

Re: Speed up processing a certain string

Posted: Wed Aug 04, 2021 9:34 am
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