Jump to content
Sign in to follow this  

I need help - StringRegExp

Recommended Posts

Hi, i need help here's a xml file i need to check some data in the xml file but the second StringRegExp return 0 why?

Here's the XML file

<entry xmlns="http://www.w3.org/2005/Atom">
   <category scheme="kind" term="post" />
   <title type="text">TITLE</title>
   <content type="html" />
   <link rel="replies" type="application/atom+xml" href="/comments/default" title="Post Comments" />
   <link rel="replies" type="text/html" href="/comment-form" title="0 Comments" />
   <link rel="edit" type="application/atom+xml" href="/" />
   <link rel="self" type="application/atom+xml" href="/" />
   <link rel="alternate" type="text/html" href="/" title="TITLE" />
   <thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total>

Autoit Script

$XML = FileRead(@ScriptDir & '\default.xml')

Local $nOffset = 1

Local $aArray
While 1
    $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 1, $nOffset)

    If @error = 0 Then
        $nOffset = @extended
    For $i = 0 To UBound($aArray) - 1
        ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1, $nOffset)); return 0!

Any help would be greatly appreciated


Share this post

Link to post
Share on other sites

The last StringRegExp should return an array, not a string.

You should use ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1, $nOffset)[0]) instead, but in your case, $nOffset is out of range.

I don't really understand why you want to use $nOffset for, but maybe this code would match with your need :

Local $XML = FileRead(@ScriptDir & '\default.xml')

Local $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 3)

If NOT @error Then
    For $i = 0 To UBound($aArray) - 1
        $aPublisher = StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1)
        ConsoleWrite ( $aPublisher[0] )
Edited by jguinch

Share this post

Link to post
Share on other sites

From your example, it's going to fail for us, you only provided 1 entry.  The return is the number of characters, then you ask it to search from that return on.  Anyway....  The first regex works for me when I double your xml example.

The ConsoleWrite(StringRegExp()) ... You know that it returns an array right?  Offset doesn't apply to that for/loop because you're accessing the data directly from the array.

So this should work if you're validating only:

ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 0) & @CRLF)
Edited by SmOke_N
Iterated validation

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post
Share on other sites

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
Sign in to follow this  

  • Create New...