Sign in to follow this  
Followers 0
LurchMan

RegEx Help

8 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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._______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

#5 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

[^.,]+.tif

Match 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 by Jury

Share this post


Link to post
Share on other sites

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

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
Sign in to follow this  
Followers 0