Jump to content

yet another StringRegExp problem--HELP


Recommended Posts

$sPattern = I"\d\d[xX]\d\d"
$sTest = "alias 01x21.avi"
$nFlag = 1
$vResult = StringRegExp($sTest, $sPattern, $nFlag)
Select
Case @Error = 1 
   msgbox(0, "", "Error.  Flag is bad.  $vResult = ''")
Case @Error = 2 
    msgbox(0, "", "Error.  The pattern was invalid.  $vResult = position in $sPattern where error occurred.")
Case @Error = 0
   if @Extended  Then
     ; Success.  Pattern matched.  $vResult has the text from the groups or true (1), depending on flag. 
      msgbox(0, "Match", $vResult)
   Else
      msgbox(0, "", "Failure.  Pattern not matched.  $vResult = '' or false (0), depending on flag.")
   EndIf
EndSelect

I cannot seem to get any resulting match, ie. '01x21'....

Can anyone help?

Thanks

Link to comment
Share on other sites

$sPattern = I"\d\d[xX]\d\d"
$sTest = "alias 01x21.avi"
$nFlag = 1
$vResult = StringRegExp($sTest, $sPattern, $nFlag)
Select
Case @Error = 1 
   msgbox(0, "", "Error.  Flag is bad.  $vResult = ''")
Case @Error = 2 
    msgbox(0, "", "Error.  The pattern was invalid.  $vResult = position in $sPattern where error occurred.")
Case @Error = 0
   if @Extended  Then
    ; Success.  Pattern matched.  $vResult has the text from the groups or true (1), depending on flag. 
      msgbox(0, "Match", $vResult)
   Else
      msgbox(0, "", "Failure.  Pattern not matched.  $vResult = '' or false (0), depending on flag.")
   EndIf
EndSelect

I cannot seem to get any resulting match, ie. '01x21'....

Can anyone help?

Thanks

<{POST_SNAPBACK}>

What is the I doing in front of the string in line 1? Flag of 1 is trying to return an array of matching text, but in order to state what should be returned, parenthese (, ) need to be put around the pattern section to be returned. If you want to just return true or false, set $nFlag to 0.

How about...

$sPattern = "\d\d[xX]\d\d"
$sTest = "alias 01x21.avi"
$nFlag = 0
$vResult = StringRegExp($sTest, $sPattern, $nFlag)
Select
Case @Error = 1 
   msgbox(0, "", 'Error.  Flag is bad.  $vResult = "" ')
Case @Error = 2 
    msgbox(0, "", "Error.  The pattern was invalid.  $vResult = position in $sPattern where error occurred.")
Case @Error = 0
   if @Extended  Then
    ; Success.  Pattern matched.  $vResult has the text from the groups or true (1), depending on flag. 
      msgbox(0, "Match", $vResult)
   Else
      msgbox(0, "", 'Failure.  Pattern not matched.  $vResult = "" or false (0), depending on flag.')
   EndIf
EndSelect

or

$sPattern = "(\d\d[xX]\d\d)"
$sTest = "alias 01x21.avi"
$nFlag = 1
$vResult = StringRegExp($sTest, $sPattern, $nFlag)
Select
Case @Error = 1 
   msgbox(0, "", 'Error.  Flag is bad.  $vResult = "" ')
Case @Error = 2 
    msgbox(0, "", "Error.  The pattern was invalid.  $vResult = position in $sPattern where error occurred.")
Case @Error = 0
   if @Extended  Then
    ; Success.  Pattern matched.  $vResult has the text from the groups or true (1), depending on flag. 
      msgbox(0, "Match", $vResult[0])
   Else
      msgbox(0, "", 'Failure.  Pattern not matched.  $vResult = "" or false (0), depending on flag.')
   EndIf
EndSelect

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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