Sign in to follow this  
Followers 0
ASut

StringRegExp pattern

6 posts in this topic

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



#2 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        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

#4 ·  Posted (edited)

"(?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

Thanks, them work fine for me.

RegExp is very difficult to learn.

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  
Followers 0