Jump to content

How i get the specified value through StringRegExp


Recommended Posts

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $aArray = 0, $iOffset = 1
        
        
        
Local $string = "<a>1</a><b>2</b><c>3</c><d>4</d><e>5</e>|<a>1-1</a><b>2-1</b><c>3-1</c><d>4-1</d><e>5-1</e>|<a>1-2</a><b>2-2</b><c>3-2</c><d>4-2</d><e>5-2</e>|"
        
        
        
While 1
    $aArray = StringRegExp($string, '(?i)<a>(.*?)</a><b>(.*?)</b><c>(.*?)</c><d>(.*?)</d><e>5-1</e>', $STR_REGEXPARRAYMATCH, $iOffset)
    If @error Then ExitLoop
    $iOffset = @extended
    For $i = 0 To UBound($aArray) - 1
        MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 1 - ", $aArray[0])
    Next
WEnd

Hello guys, how i get data from <a>?</a> where condition <e>5-1</e> in one time runing?  (not in while loop?)

Thanks a lot!

Edited by powerofos
Link to post
Share on other sites

What about this?

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

;Local $aArray = 0, $iOffset = 1



Local $string = "<a>1</a><b>2</b><c>3</c><d>4</d><e>5</e>|<a>1-1</a><b>2-1</b><c>3-1</c><d>4-1</d><e>5-1</e>|<a>1-2</a><b>2-2</b><c>3-2</c><d>4-2</d><e>5-2</e>|"

Global $g_aStringSplit = StringSplit($string, Chr(124), $STR_NOCOUNT)

For $i = 0 To (UBound($g_aStringSplit) - 1) Step 1
    If StringRegExp($g_aStringSplit[$i], '(?i)<a>(.*?)</a><b>(.*?)</b><c>(.*?)</c><d>(.*?)</d><e>5-1</e>', $STR_REGEXPMATCH) = 1 Then
        Global $g_aArray = StringRegExp($g_aStringSplit[$i], '(?i)<a>(.*?)</a><b>(.*?)</b><c>(.*?)</c><d>(.*?)</d><e>(.*?)</e>', $STR_REGEXPARRAYMATCH)
        _ArrayDisplay($g_aArray)
    EndIf
Next


;~ While 1
;~     $aArray = StringRegExp($string, '(?i)<a>(.*?)</a><b>(.*?)</b><c>(.*?)</c><d>(.*?)</d><e>5-1</e>', $STR_REGEXPARRAYMATCH, $iOffset)
;~     If @error Then ExitLoop
;~     $iOffset = @extended
;~     For $i = 0 To UBound($aArray) - 1
;~         MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 1 - ", $aArray[0])
;~     Next
;~ WEnd

 I'm not the best with RegEX though. I'm sure you'll get some better solutions.

Link to post
Share on other sites

How about this one :

#include <Array.au3>

Local $string = "<a>1</a><b>2</b><c>3</c><d>4</d><e>5</e>|<a>1-1</a><b>2-1</b><c>3-1</c><d>4-1</d><e>5-1</e>|<a>1-2</a><b>2-2</b><c>3-2</c><d>4-2</d><e>5-2</e>|"
Local $aArray =  StringRegExp($string,"(?i)<a>(.{1,3})</a><b>.{1,3}</b><c>.{1,3}</c><d>.{1,3}</d><e>5-1</e>", 1)
_ArrayDisplay($aArray)

 

Link to post
Share on other sites
Posted (edited)

For a bit of versatility (and for fun)

#include <Array.au3>

Local $string = "<a>1</a><b>2</b><c>3</c><d>4</d><e>5</e>|<a>1-1</a><b>2-1</b><c>3-1</c><d>4-1</d><e>5-1</e>|<a>1-2</a><b>2-2</b><c>3-2</c><d>4-2</d><e>5-2</e>|"

$var = "b"
$if = "5-2"
Local $aArray =  StringRegExp($string, '<' & $var & '>(.{1,3})</' & $var & '>[^\|]*<e>' & $if & '</e>', 1)
_ArrayDisplay($aArray)

 

Edited by mikell
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...