Sign in to follow this  
Followers 0
Trolleule

Need help to find right pattern for StringRegExp

3 posts in this topic

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)

Share this post


Link to post
Share on other sites



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)

Share this post


Link to post
Share on other sites

fuck you are awesome  :thumbsup:

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