Jump to content

RegEx Question


Recommended Posts

Hi,

im using this statement to get a specific content between two tags:

StringRegExp($content,'<resource>xy:/resources/([^<]*)<\/resource>',3)

It works fine. But now i have to add a functionality, because it can happen, that after "<resource" another tags comes up, but the regex should ignore it

the content can be like this

<resource>xy:/resources/xyz/123</resource>
<resource mytag="xy">xy:/resources/xyz/123</resource>

what do i have to change to my rule, that is has something like

StringRegExp($content,'<resource I_DONT_CARE_WHAT_STANDS_HERE>xyz:/resources/([^<]*)<\/resource>',3)

any ideas?

Link to comment
Share on other sites

  • Developers

just a stab:

StringRegExp($content,'<resource.*?>xy:/resources/([^<]*)<\/resource>',3)

Post a runnable test script when you want it confirmed as I am way too lazy to have to type that myself. ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You might try to do it backwards  :)

#Include <Array.au3>

$content = '<resource>xy:/resources/xyz/123</resource>' & @crlf & _ 
        '<resource mytag="xy">xy:/resources/xyz/456</resource>'

$res = StringRegExp($content,'([^/]+)</resource>', 3)
; or this, depending of the expected result
; $res = StringRegExp($content,'([^/]+/[^/]+)</resource>', 3)

_ArrayDisplay($res)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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