Jump to content

StringRegexp capture file name


Recommended Posts

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)
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...