Guest cybrsrfr Posted September 7, 2005 Posted September 7, 2005 With StringRegExp from the beta verison. I havecreated a basic xml tag parser. Unfortunately iftags using the following reg pattern$pattern = "<(?i)"&$tag&">(.*?)</(?i)"&$tag&">"against the following string$stext = "<test>a</test> <test>b</test> <test>c</Test>"result: a, b and cif there is no space between the tags$stext = "<test>a</test><test>b</test><test>c</Test>"result: aHow can the regular expression pattern be changed toget a result whether there is a space or not?Any help is appreciated. My goal is to create a simple function to read a simple xmlconfig file into an array. Without needing an external parser (.dll).Func tagarray($tag, $stext) $pattern = "<(?i)"&$tag&">(.*?)</(?i)"&$tag&">" $resultarray = StringRegExp($stext,$pattern,3) $error = @error If @error = 0 and @extended = 1 Then return $resultarray Else ;msgbox(0,"error","@error = "& $error & @CRLF & "@extended = " & @extended) return 0 EndIf return EndFunc $stext = "<Test>a</test><test>b</test> <test>c</Test>" $tag = "test" $resultarray = tagarray($tag, $stext) For $i = 0 To UBound($resultarray) - 1 MsgBox(0, "Result", $resultarray[$i]) Next
Valuater Posted September 8, 2005 Posted September 8, 2005 (edited) First nice code. I have never applied myself enough to completely understand StringRegExp However I can get where ever i want with string controls $test = "<Test>a</test><test>b</test> <test>c</Test>" for $x = 1 to 1000 $L_loc = StringInStr($test, "</test>") If @error then ExitLoop $result = StringTrimLeft( $test, $L_loc -2) $result_2 = StringLeft( $result, 1) $result_3 = StringTrimLeft($result, 3) $test = $result_3 If $result_2 <> "" Then MsgBox(0,"test", "final result = " & $result_2) EndIf Next maybe this can help you 8) Edited September 8, 2005 by Valuater
Guest cybrsrfr Posted September 8, 2005 Posted September 8, 2005 Thanks for sharing the alternative method. I found a work around to the problem. Its seems like StringRegExp gets one character ahead of itself. So with that in mind changing the pattern to the following works.$pattern = "<(?i)"&$tag&">(.*?)</(?i)"&$tag;removed the final &">"$test = "<Test>a</test><test>b</test> <test>c</Test>" ;example search stringWith this regular epression pattern it looks for "<test>c</test"and that leaves the final ">" as an extra character and withthat extra character it finds all ocurrences of the tag.First nice code. I have never applied myself enough to completely understand StringRegExpHowever I can get where ever i want with string controls$test = "<Test>a</test><test>b</test> <test>c</Test>" for $x = 1 to 1000 $L_loc = StringInStr($test, "</test>") If @error then ExitLoop $result = StringTrimLeft( $test, $L_loc -2) $result_2 = StringLeft( $result, 1) $result_3 = StringTrimLeft($result, 3) $test = $result_3 If $result_2 <> "" Then MsgBox(0,"test", "final result = " & $result_2) EndIf Nextmaybe this can help you8)<{POST_SNAPBACK}>
Nutster Posted September 8, 2005 Posted September 8, 2005 It should not be dropping that last character (or picking up an extra, depending on your point of view). I will investigate and get back to you. David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd...
Nutster Posted September 9, 2005 Posted September 9, 2005 This is the result of a bug in StringRegExp. I will investigate this weekend and see if I can fix it for the next Beta distribution. David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now