ASut Posted June 26, 2011 Share Posted June 26, 2011 Hi, How can I modify the pattern to make it the output as below 1 ABC 123ABCinstead of 1 12<test>ABC 123ABCWhich 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted June 26, 2011 Developers Share Posted June 26, 2011 (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 June 26, 2011 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. Link to comment Share on other sites More sharing options...
ASut Posted June 26, 2011 Author Share Posted June 26, 2011 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 26, 2011 Moderators Share Posted June 26, 2011 (edited) "(?i)<test>(.+?)(?=<)" Edited June 26, 2011 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. Link to comment Share on other sites More sharing options...
Malkey Posted June 26, 2011 Share Posted June 26, 2011 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 Link to comment Share on other sites More sharing options...
ASut Posted June 27, 2011 Author Share Posted June 27, 2011 Thanks, them work fine for me. RegExp is very difficult to learn. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now