HurleyShanabarger

StringRegExp

11 posts in this topic

Hello,

I need to process texts similair to this one:

Test gXX_ThisAndThat.boWhatIs Up = Cheese;
Lorem ipsum dolor sit amet, consectetur adipisici elit, 
sed eiusmod tempor incidunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquid ex ea commodi consequat.
Test gXX_ThisAndThat.boWhatIs Up = Cheese;
Lorem ipsum dolor sit amet, consectetur adipisici elit, 
sed eiusmod tempor incidunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquid ex ea commodi consequat.
Test gXX_ThisAndThat.boWhatIs Up = Cheese;
Lorem ipsum dolor sit amet, consectetur adipisici elit, 
sed eiusmod tempor incidunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquid ex ea commodi consequat.

It is requested to find the lines with the XX part.

I am using this expression:

$aRegExp = StringRegExp($sText, "([a-z])XX_(.*)", 3)

As result I am getting this:

0 => g
1 => ThisAndThat.boWhatIs Up = Cheese;
2 => g
3 => ThisAndThat.boWhatIs Up = Cheese;
4 => g
5 => ThisAndThat.boWhatIs Up = Cheese;

What I want to receive is this:

0 => gXX_ThisAndThat.boWhatIs Up = Cheese;
1 => gXX_ThisAndThat.boWhatIs Up = Cheese;
2 => gXX_ThisAndThat.boWhatIs Up = Cheese;

Is there anyway to get this result with an improved RegExp? Is it also possible to receive the line number?

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#include <Array.au3>

$sTest = "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
"Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
"sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
"aliquid ex ea commodi consequat." & @CRLF & _
"Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
"Lorem ipsum dolor sit amet, consectetur adipisici elit," & @CRLF & _
"sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
"aliquid ex ea commodi consequat." & @CRLF & _
"Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
"Lorem ipsum dolor sit amet, consectetur adipisici elit," & @CRLF & _
"sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
"aliquid ex ea commodi consequat."

$aResult = StringRegExp($sTest, "(?im)^.*XX.*$", 3)
_ArrayDisplay($aResult)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

HurleyShanabarger,

How about this: :)

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

$sText = "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
    "Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
    "sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
    "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
    "aliquid ex ea commodi consequat." & @CRLF & _
    "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
    "Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
    "sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
    "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
    "aliquid ex ea commodi consequat." & @CRLF & _
    "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
    "Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
    "sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
    "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
    "aliquid ex ea commodi consequat."

$aLines = StringSplit($sText, @CRLF, $STR_ENTIRESPLIT + $STR_NOCOUNT)
$iLines = UBound($aLines) - 1

Local $aRet[$iLines][2], $iCount = 0

For $i = 0 To $iLines
    If StringInStr($aLines[$i], "XX") Then
        $aRet[$iCount][0] = $i
        $aRet[$iCount][1] = StringRegExpReplace($aLines[$i], ".*([a-z]XX_.*)", "$1")
        $iCount += 1
    EndIf
Next
Redim $aRet[$iCount][2]

_ArrayDisplay($aRet, "", Default, 8)
You will need a real RegEx guru to get it all in one pass. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi UEZ,

very nice. Modified it to this:

Dim $sTest
$sTest &= "Test 1 gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sTest &= "Test 2 gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sTest &= "Test 3 GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sTest &= "Test 4 GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sTest &= "Test 5 gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sTest &= "Test 6 gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF

$aResult = StringRegExp($sTest, "(?m)^.*[a-z]{1}XX_.*$\s", 3)
_ArrayDisplay($aResult)

With thsi pattern I get exactly what I need as result: only the line with Test 1.

Any idea about the line number (other then looping trough the file)

EDIT:

Thanks Melba23, I think I will combine both solutions :)

Edited by HurleyShanabarger

Share this post


Link to post
Share on other sites

I removed the s otherwise @crlf will be added, too!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

with line number

#include <File.au3>
 #include <Array.au3>

Dim $aFile

_FileReadToArray("testdoc.txt" , $aFile)

for $i = 1 to ubound($aFile) - 1
    $aFile[$i] = $i & ":  " & $aFile[$i]
next

for $i = ubound($aFile) - 1 to 1 step -1
    If Not StringinStr($aFile[$i] , "gXX_" , 1) Then _ArrayDelete($aFile , $i)
Next

_ArrayDelete($aFile , 0)
_ArrayDisplay($aFile)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Try this.

#include <Array.au3>

$sText = "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
        "Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
        "sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
        "aliquid ex ea commodi consequat." & @CRLF & _
        "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
        "Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
        "sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
        "aliquid ex ea commodi consequat." & @CRLF & _
        "Test gXX_ThisAndThat.boWhatIs Up = Cheese;" & @CRLF & _
        "Lorem ipsum dolor sit amet, consectetur adipisici elit, " & @CRLF & _
        "sed eiusmod tempor incidunt ut labore et dolore magna aliqua." & @CRLF & _
        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" & @CRLF & _
        "aliquid ex ea commodi consequat."

$aRet = StringRegExp($sText, ".XX_.+", 3) ; Matches the character before "XX_", and captures all characters to the end of that line.
; By default, DotAll is off. Therefore, dot, ".", will not match newline characters.

_ArrayDisplay($aRet)

#cs ;Returns:-
gXX_ThisAndThat.boWhatIs Up = Cheese;
gXX_ThisAndThat.boWhatIs Up = Cheese;
gXX_ThisAndThat.boWhatIs Up = Cheese;
#ce

Share this post


Link to post
Share on other sites

Thank you all. Here is what I created with your help:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #Tidy_Parameters=/reel /sf /ri
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Region Include
    #include <Array.au3>
#EndRegion Include

#Region Prog
    Dim $_m_sString
    $_m_sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
    $_m_sString = StringStripCR($_m_sString)
    
    Dim $_m_aRegEx = StringRegExp($_m_sString, "(?m)^.*[a-z]{1}[A-Z]{2}_.*$", 3)
    Dim $_m_aLines = _String_LinesFromArray($_m_sString, $_m_aRegEx)

    _ArrayDisplay($_m_aLines)
#EndRegion Prog

#Region Functions
    Func _String_ChrCnt(Const $_c_sString, Const $_c_sSearch)
        ;|-----------------------------------|
        ;| Return the char count in a string |
        ;|-----------------------------------|
        ;| $_c_sString = String              |
        ;| $_c_sSearch = Char to count       |
        ;|-----------------------------------|

        StringReplace($_c_sString, $_c_sSearch, "")
        Return @extended
    EndFunc   ;==>_String_ChrCnt

    Func _String_LinesFromArray(Const $_c_sString, Const ByRef $_c_aArray)
        ;|--------------------------------------------------|
        ;| Get line-number of matches from string           |
        ;|--------------------------------------------------|
        ;| $_c_sString = The string that should be searched |
        ;| $_c_aArray = Array with matches                  |
        ;|--------------------------------------------------|

        ;|------------------------------------------------------------------------------------------------------------|
        ;|------------------------------------------ Check input variables -------------------------------------------|
        ;|------------------------------------------------------------------------------------------------------------|
        If $_c_sString = "" Then Return SetError(1)
        If Not IsArray($_c_aArray) Then Return SetError(2)

        ;|------------------------------------------------------------------------------------------------------------|
        ;|------------------------------------------ Create local variables ------------------------------------------|
        ;|------------------------------------------------------------------------------------------------------------|
        Local $_l_aLine[UBound($_m_aRegEx)][2]
        Local $_l_sTemp = $_c_sString, $_l_iIndex = -1

        ;|------------------------------------------------------------------------------------------------------------|
        ;|------------------------------------------- Loop trough matches --------------------------------------------|
        ;|------------------------------------------------------------------------------------------------------------|
        For $_l_iLoop = 0 To UBound($_c_aArray) - 1
            ;|--------------------------------------------------------------------------------------------------------|
            ;|                                      Find position of RegEx match                                      |
            ;|--------------------------------------------------------------------------------------------------------|
            $_l_iPos = StringInStr($_l_sTemp, $_c_aArray[$_l_iLoop], 1, 1)
            If Not $_l_iPos Then ContinueLoop

            ;|--------------------------------------------------------------------------------------------------------|
            ;|                               Count linebreak up to the pos of the match                               |
            ;|--------------------------------------------------------------------------------------------------------|
            $_l_iIndex += _String_ChrCnt(StringLeft($_l_sTemp, $_l_iPos - 1), @LF)

            ;|--------------------------------------------------------------------------------------------------------|
            ;|                                          Write data to array                                           |
            ;|--------------------------------------------------------------------------------------------------------|
            $_l_aLine[$_l_iLoop][1] = $_c_aArray[$_l_iLoop]
            $_l_aLine[$_l_iLoop][0] = $_l_iIndex + 2

            ;|--------------------------------------------------------------------------------------------------------|
            ;|                                     Remove string left up to match                                     |
            ;|--------------------------------------------------------------------------------------------------------|
            $_l_sTemp = StringTrimLeft($_l_sTemp, $_l_iPos + StringLen($_c_aArray[$_l_iLoop]) - 1)
        Next

        Return $_l_aLine
    EndFunc   ;==>_String_LinesFromArray
#EndRegion Functions

Of course I missed to explain that i want to catch everything that has the pattern "[a-z]{1}[A-Z]{2}_" but I was able to figure that out :)

Do you think there is room for improvement?

Share this post


Link to post
Share on other sites

I think this is easier to follow, but I am bias.

#include <Array.au3>

Local $sString
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF

Local $aRegEx = StringRegExp($sString, "(?m)^.*[a-z]{1}[A-Z]{2}_.*$", 3)
Local $aLine[UBound($aRegEx)][2]

For $i = 0 To UBound($aRegEx) - 1
    StringRegExpReplace(StringRight($sString, StringInStr($sString, $aRegEx[$i], 1, $i + 1)), "(.+)","")
    $aLine[$i][0] = @extended + 1
    $aLine[$i][1] = $aRegEx[$i]
Next

_ArrayDisplay($aLine)

Share this post


Link to post
Share on other sites

For the fun only :

#include <Array.au3>

Local $sString
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF

$aResult = StringRegExp ( Execute('"' & StringRegExpReplace( StringReplace($sString, '"', '""')  , "((?<=\A)|(?<=\n))(?!\Z)", '" & StringRegExpReplace( Assign("i", Eval("i") + 1), "\\d", "(Line " & Eval("i") & ") ") & "') & '"'),   "(?m)^(.*[a-z]{1}[A-Z]{2}_.*).*$", 3)
_ArrayDisplay($aResult)

Share this post


Link to post
Share on other sites

:thumbsup:

For the fun indeed, but the approach is very interesting and you should have given some more explanations about the 2 steps you used in this huge expression
I personally will store this concept in my regex library  :)

#include <Array.au3>

Local $sString
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay GXx_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXXThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXxThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gsdXsdX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF
$sString &= "Here we go and we stay gXX_ThisAndThat.boWhatIsXX = Cheese;" & @CRLF

; replace each start of line by the corresponding line number (insert the line nbr) using an incrementing $i variable

$sTmp = Execute('"' & StringRegExpReplace( $sString , "(?m)^", '" & StringReplace( Assign("i", Eval("i")+1), "1",  Eval("i") ) & "  ') & '"') 
Msgbox(0,"", $sTmp)

; then apply the regex filter to keep the wanted lines only

$aResult = StringRegExp ($sTmp, "(?m)^(.*[a-z]{1}[A-Z]{2}_.*).*$", 3)
_ArrayDisplay($aResult)

 

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