LurchMan Posted February 14, 2013 Share Posted February 14, 2013 Hello All - I'm using the following string and trying to get just the *.tif name inbetween the quotes: "901676","3rdparty","00019596.tif","THIRD PARTY REPORTS","Appraisal","Page", And I'm using the RegEx: $aResults = StringRegExp ($sStr, '\"(.*?)\.tif') This returns 901676","3rdparty","00019596 I am unsure of where my pattern is wrong, I'm horrible with RegEx! Any help is appreciate for where my pattern is wrong. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 14, 2013 Share Posted February 14, 2013 (edited) This would probably work#include <Array.au3> $sStr = '"901676","3rdparty","00019596.tif","THIRD PARTY REPORTS","Appraisal","Page",' $aResults = StringRegExp ($sStr, '"[^.,]+.tif"', 3) _ArrayDisplay( $aResults ) Edit: There is no need to escape a quote and to receive an array flag 3 has to be used Regards Edited February 14, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
LurchMan Posted February 14, 2013 Author Share Posted February 14, 2013 This would probably work#include <Array.au3> $sStr = '"901676","3rdparty","00019596.tif","THIRD PARTY REPORTS","Appraisal","Page",' $aResults = StringRegExp ($sStr, '"[^.,]+.tif"', 3) _ArrayDisplay( $aResults ) Absolutely perfect! Thank You! Could you explain that pattern to me please? Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2013 Moderators Share Posted February 14, 2013 LurchMan, How about this: $sString = '"901676","3rdparty","00019596.tif","THIRD PARTY REPORTS","Appraisal","Page",' $sExtract = StringRegExpReplace($sString, '.*"(.*tif)".*', '$1') MsgBox(0, "Extract", $sExtract) 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 Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 14, 2013 Share Posted February 14, 2013 (edited) Decode"[^.,]+.tif" - Match Character which is not a dot(.) or a comma(,) greedily after which a ".tif" is present These characters must be enclosed in quotes(double)Do feel free to ask about any doubts Edited February 14, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
LurchMan Posted February 14, 2013 Author Share Posted February 14, 2013 Decode"[^.,]+.tif" - Match Character which is not a dot(.) or a comma(,) greedily after which a ".tif" is present These characters must be enclosed in quotes(double) Do feel free to ask about any doubts No doubts here. I just want to learn what's actually happening with the solutions I've given on here. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
Jury Posted February 16, 2013 Share Posted February 16, 2013 (edited) [^.,]+.tifMatch a single character NOT present in the list ".," «[^.,]+»Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»Match any single character «.»Match the characters "tif" literally «tif» Edited February 16, 2013 by Jury Link to comment Share on other sites More sharing options...
Malkey Posted February 16, 2013 Share Posted February 16, 2013 This example is using a trickier test string. Local $sTestString = '" 901676.tif","3rdparty",''00019596.tiff'',"THIRD PARTY REPORTS","Appraisal", Page One.TIF,"last"' ;(?i) - Allows upper-case and lower-case TtIiFf to be captured. ; \b - Prevent leading spaces to be captured in the file name. ; [^"'',]+ - Capture all characters that are not a double or single quote or a coma. ; \.tif - Capture the literals .tif ; f? - Capture the literals f if it exist - Same as f{0,1}. ; This pattern returns the tif file names between the double or single quotes if the quote characters exist. ; Quote characters are not returned. Local $aResults = StringRegExp($sTestString, '(?i)\b[^"'',]+\.tiff?', 3) __ArrayDisplay($aResults) ; ------- Display Array -------- Func __ArrayDisplay(ByRef $array) Local $sArrayDisplay = "Row" & @TAB & "Col 0" & @CRLF & "------------------------" & @CRLF For $i = 0 To UBound($array) - 1 $sArrayDisplay &= " [" & $i & "]" & @TAB & $array[$i] & @CRLF Next MsgBox(0, "ArrayDisplay", $sArrayDisplay) EndFunc ;==>__ArrayDisplay Link to comment Share on other sites More sharing options...
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