Jump to content
Sign in to follow this  
tbaror

StringRegexp capture file name

Recommended Posts

tbaror

Hello,

i am trying to capture file name in a string might be for example "-configfile te56stds -r 8798" or "-configfile te56stds.conf -r 8798"

i figure out pattern like example below but i cant get it works

please advice

Thanks

$cliArray   = '(?:-configfile) ([.*\..{4}] [.*$])' 

 $cliArra  = StringRegExp("-configfile te56stds.  -r 8798",$cliArray  ,2)

Share this post


Link to post
Share on other sites
tbaror

Hello,

i am trying to capture file name in a string might be for example "-configfile te56stds -r 8798" or "-configfile te56stds.conf -r 8798"

i figure out pattern like example below but i cant get it works

please advice

Thanks

$cliArray   = '(?:-configfile) ([.*\..{4}] [.*$])' 

 $cliArra  = StringRegExp("-configfile te56stds.  -r 8798",$cliArray  ,2)

Share this post


Link to post
Share on other sites
Authenticity

Metacharacters like . or * doesn't govern their true meaning within character class [...] so it's erroneous pattern or at least it doesn't match exactly what you want it to match.

Example:

#include <Array.au3>

Dim $sRawText = "-configfile te56stds.conf -r 8798"
Dim $sPattern = '-configfile\s*((?:"[^"]++"|[^ ]++)\s*-r\s*\d++)'

Dim $aMatches = StringRegExp($sRawText, $sPattern, 1)
If IsArray($aMatches) Then _ArrayDisplay($aMatches)

$sRawText = "-configfile C:\Configuration\te56stds.conf -r 8798"
$aMatches = StringRegExp($sRawText, $sPattern, 1)
If IsArray($aMatches) Then _ArrayDisplay($aMatches)

$sRawText = '-configfile "C:\Con fi gu rat ion\te56stds.conf" -r 8798'
$aMatches = StringRegExp($sRawText, $sPattern, 1)
If IsArray($aMatches) Then _ArrayDisplay($aMatches)

$sRawText = '-configfil "C:\Con fi gu rat ion\te56stds.conf -r 8798'
$aMatches = StringRegExp($sRawText, $sPattern, 1)
If IsArray($aMatches) Then _ArrayDisplay($aMatches) ; No match

If you want to partition the elements to - "-configfile"(don't capture), "file"(capture), "-r"(don't capture), "number"(capture), use just parentheses where you want to capture and leave the rest outside of it. Also, 2 is the whole match, even what you don't want to capture.

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

isn't it this what you want?

#include <Array.au3>

Dim $sRawText[3] = ['-configfile te56stds.conf -r 8798"', '-configfile "c:\Daten und Einstellungen\te56stds.conf" -r 8798"', '"-configfile te56stds -r 8798"']
Dim $sPattern = '-configfile\s*"*(.*?)(?="|-)'

For $i = 0 To UBound($sRawText) - 1
    Dim $aMatches = StringRegExp($sRawText[$i], $sPattern, 3)
    If IsArray($aMatches) Then _ArrayDisplay($aMatches)
Next

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
mary

2 solutions:

1- simple one:

juste use $Array=stringsplit("your string here", " ",1)

2-with Regexp:

$s="-configfile te56stds -r 8798" 
$Array=StringRegExp($s, "(\w+)",3)

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

second time?

#include <Array.au3>

Dim $sRawText[3] = ['-configfile te56stds.conf -r 8798"', '-configfile "c:\Daten und Einstellungen\te56stds.conf" -r 8798"', '"-configfile te56stds -r 8798"']
Dim $sPattern = '-configfile\s*"*(.*?)(?="|-)'

For $i = 0 To UBound($sRawText) - 1
    Dim $aMatches = StringRegExp($sRawText[$i], $sPattern, 3)
    If IsArray($aMatches) Then _ArrayDisplay($aMatches)
Next

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
tbaror

Thanks All

Edited by tbaror

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  

×