Trolleule Posted November 7, 2014 Share Posted November 7, 2014 Hi, can someone help me to get the right pattern: I have the string: gdf<font>My</font><font>Test</font>String<font>Hello</font> End And the array should look like: 1. gdf 2. <font>My</font> 3. <font>Test</font> 4. String 5. <font>Hello</font> 6. End I tried it in so many different ways but can't get it work. #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> Local $string = _ 'rtzrtzrtz' & _ '<test>a</test> ' & _ '<test>b</test>fgdfgd' & _ '<test>c</Test> ' Local $test = _ ' gdf' & _ '<font>My</font>' & _ '<font>Test</font>String' & _ '<font>Hello</font> End' ConsoleWrite("$test: " & $test & @CRLF) ;~ Local $aArray = StringRegExp($string, '(?i)(.+?)(<test.*?>.*?</test>)', 3) ;~ _ArrayDisplay($aArray) Local $aArray = StringRegExp($test, '(?i)(.+?)(<font>.*?</font>)', 3) Local $aArray2 = StringRegExp($test, '(?i)(?m)(.*?)(<font>.*?</font>*|$)', 3) ;~ _ArrayDisplay($aArray) _ArrayDisplay($aArray2) Link to comment Share on other sites More sharing options...
Solution Malkey Posted November 7, 2014 Solution Share Posted November 7, 2014 The trailing space in the $string variable:- "' '<test>a</test> ' & _" will cause a blank array element when using the regex pattern '[^><]+|(<[^>]+>[^<]+</[^>]+>)'. Using the regex pattern '[^><h]+|(<[^>]+>[^<]+</[^>]+>)', the blank element in the array will not occur. #include <Array.au3> Local $string = _ 'rtzrtzrtz' & _ '<test>a</test> ' & _ ; Note trailing space this line. '<test>b</test>fgdfgd' & _ '<test>c</Test> ' Local $test = _ ' gdf' & _ '<font>My</font>' & _ '<font>Test</font>String' & _ '<font>Hello</font> End' Local $aArray = StringRegExp($string, '[^><\h]+|(<[^>]+>[^<]+</[^>]+>)', 3) ; With \h present, there is no blank element in the array. _ArrayDisplay($aArray) Local $aArray2 = StringRegExp($test, '[^><]+|(<[^>]+>[^<]+</[^>]+>)', 3) _ArrayDisplay($aArray2) Link to comment Share on other sites More sharing options...
Trolleule Posted November 7, 2014 Author Share Posted November 7, 2014 fuck you are awesome 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