Jump to content

Recommended Posts

Guest cybrsrfr
Posted

With StringRegExp from the beta verison. I have

created a basic xml tag parser. Unfortunately if

tags

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 c

if there is no space between the tags

$stext = "<test>a</test><test>b</test><test>c</Test>"

result: a

How can the regular expression pattern be changed to

get 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 xml

config 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
Posted (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 by Valuater

NEWHeader1.png

Guest cybrsrfr
Posted

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 string

With this regular epression pattern it looks for "<test>c</test"

and that leaves the final ">" as an extra character and with

that extra character it finds all ocurrences of the tag.

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)

<{POST_SNAPBACK}>

Posted

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 Nuttall
Nuttall 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...

Posted

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 Nuttall
Nuttall 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...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...