xcaliber13 Posted June 2, 2016 Posted June 2, 2016 Hey Everyone, I am having a problem getting this regex to work. I downloaded and installed Expresso to help make and test the search expression. Using Expresso this pattern pulls the whole line of text. (?m)^(\bPID\b|\bGT1\b).* Any line that begins with PID or GT1 So I am thinking great just put that into my AutoIt script and good to go....But in AutoIt it is only pulling just the string PID or GT1 not the whole line of text. $aResults = StringRegExp($sFile, "(?m)^(\bPID\b|\bGT1\b).*", 3) Any help would be great Thank you
Moderators Melba23 Posted June 2, 2016 Moderators Posted June 2, 2016 xcaliber13, This seems to work for me: #include <Array.au3> $sText = "PID-Line 1" & @CRLF & _ "Fred-Line 2" & @CRLF & _ "GT1-Line 3" & @CRLF & _ "Fred-Line 4" $aRet = StringRegExp($sText, "(?m)^(PID.*|GT1.*)$", 3) _ArrayDisplay($aRet, "", Default, 8) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mikell Posted June 2, 2016 Posted June 2, 2016 (edited) The .* must be included in the capturing group $aResults = StringRegExp($sFile, "(?m)^(\bPID\b.*|\bGT1\b.*)", 3) ; or $aResults = StringRegExp($sFile, "(?m)^((?:\bPID\b|\bGT1\b).*)", 3) Edited June 2, 2016 by mikell
xcaliber13 Posted June 2, 2016 Author Posted June 2, 2016 mikeII, Thank you! Ya got me going in the right direction. Here is what is working. It pulls the complete line if it begins with PID or GT1 $aResults = StringRegExp($sFile, "(?m)^(\bPID\b.*|\bGT1\b.*)", 3) Again Thank you
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