Sign in to follow this  
Followers 0
jamesband

yet another StringRegExp problem--HELP

3 posts in this topic

$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

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

That looks like it is getting it... thanks!

JamesBand

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