Jump to content
Sign in to follow this  
ASut

StringRegExp pattern

Recommended Posts

Hi, How can I modify the pattern to make it the output as below

1
ABC
123ABC
instead of

1
12<test>ABC
123ABC
Which means ignore the broken tag.

Thanks in advance.

$array = StringRegExp('<test>1</test> <test>12<test>ABC</test> <test>123ABC</Test>', '<(?i)test>(.*?)</(?i)test>',3)
for $i = 0 to UBound($array) - 1
    msgbox(0, "Test - " & $i, $array[$i])
Next

Share this post


Link to post
Share on other sites

You are sure that this bit is really the input: "<test>12<test>ABC" and is not "<test>12</test>ABC"?

if so try: '<(?i)test>(.*?)<[/](?i)test>'

Jos :)

Edited by 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.
  :)

Share this post


Link to post
Share on other sites

You are sure that this bit is really the input: "<test>12<test>ABC" and is not "<test>12</test>ABC"?

if so try: '<(?i)test>(.*?)<[/](?i)test>'

Jos :)

I'm very sure it is "<test>12<test>ABC</test>".

But the pattern is not work for me.

Btw, thanks for the help.

Share this post


Link to post
Share on other sites

"(?i)<test>(.+?)(?=<)"

Edited by SmOke_N
Needed a "Look Ahead" pattern

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

Hi, How can I modify the pattern to make it the output as below

1
ABC
123ABC

...

Try this.

#Include <Array.au3>

; Positive assertions of both look behind and look ahead.
;$array = StringRegExp('<test>1</test> <test>12<test>ABC</test> <test>123ABC</Test>', "(?i)(?<=<test>)([^<]+)(?=</test>)" ,3)
;or
;$array = StringRegExp('<test>1</test> <test>12<test>ABC</test> <test>123ABC</Test>', "(?i)(?:<test>)([^<]+)(?:</test>)" ,3)
;or
$array = StringRegExp('<test>1</test> <test>12<test>ABC</test> <test>123ABC</Test>', "(?i)(?:>)([^<]+)(?:</)" ,3)

_ArrayDisplay($array)

#cs
All patterns return an array of:-
1
ABC
123ABC
#ce

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...