Jump to content

Help with group's regex


Luigi
 Share

Recommended Posts

Greetings,

Someone can help-me with this regex?
 

start1 a,b,c aaa,bbb,ccc dd,ee,ff a1,a2,a3 b1,b2,b3 c1,c2,c3 end1

start2 aa,bb,cc dd,ee,ff a1,a2,a3 b1,b2,b3 c1,c2,c3 end2

Obs: have multiples start? - end?
each block have 3 words, each word have numbers, latters with any lenght

 

Need catch an array
 

$arr1 = ["a", "b", "c", "aaa", "bbb", "ccc", "dd", "ee", "ff", "a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]

$arr2 = ["aa", "bb", "cc", "dd", "ee", "ff", "a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]

Best regards.

 

 

This is not clever...
But resolve with 2 regex...

Is possible solve this with one regex?

Local $regex1 = "(?s)start1(.*?)end1"
    Local $regex2 = "\w+"

    Local $raw_antes = " start1 aa,bb,cc dd,ee,ff g,h,i @ end1 "

    Local $arr = StringRegExp($raw_antes, $regex1, 3)
    If IsArray($arr) Then
        $arr = $arr[0]
        ConsoleWrite("@Ok1" & @LF)

        $arr = StringRegExp($arr, $regex2, 3)
        If IsArray($arr) Then
            For $ii = 0 To UBound($arr, 1) - 1 Step 3
                ConsoleWrite($arr[$ii] & ", " & $arr[$ii + 1] & ", " & $arr[$ii + 2] & @LF)
            Next
        Else
            ConsoleWrite("@Erro2" & @LF)
        EndIf
    Else
        ConsoleWrite("@Erro1" & @LF)
    EndIf

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

Or a non regexp ?

#include <Array.au3>

$sTxt1 = "start1 a,b,c aaa,bbb,ccc dd,ee,ff a1,a2,a3 b1,b2,b3 c1,c2,c3 end1"
$sTxt2 = "start2 aa,bb,cc dd,ee,ff a1,a2,a3 b1,b2,b3 c1,c2,c3 end2"

$a1 = StringSplitEX ($sTxt1)
_ArrayDisplay ($a1)
$a2 = StringSplitEX ($sTxt2)
_ArrayDisplay ($a2)

Func StringSplitEX ($sString)
  Local $aArray = StringSplit ($sString, ", ", $STR_CHRSPLIT+$STR_NOCOUNT)
  _ArrayDelete ($aArray, "0;" & UBound($aArray)-1)
  Return $aArray
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...