Sign in to follow this  
Followers 0
philkryder

StringInStr finds Search String - StringRegExp does not

3 posts in this topic

The reproducer below shows two string searches.
First using StringInStr.
Then using StringRegExp.

Both succeed when the $sPattern is 'eader">Special Circumstances'
But if a single letter "h" is added to the front of the $sPattern,
making the sPattern  'header">Special Circumstances'
the StringRegExp fails to match
While  StringInStr succeeds.
? What am I doing wrong ?
 

;;;;;;;;;;;;;;;;123456789012345678901
Opt("MustDeclareVars",1)
ConsoleWrite(@CR)

Local $ierrorSave
Local $iextendedSave
Local $iOffsetStringInString
Local $iMatchNoMatchIndicator

Local $sHTML
Local $sPattern
        ;         1         2         3         4         5
        ;12345678901234567890123456789012345678901234567890
$sHTML ='<h2 class="groupHeader">Special Circumstances</h2>'


$sPattern = 'header">Special Circumstances'
ConsoleWrite("...............................$sPattern>" & $sPattern & "<" &  @CR)


$iOffsetStringInString = StringInStr($sHTML,$sPattern)
$ierrorSave = @error
$iextendedSave = @extended
ConsoleWrite("$iOffsetStringInString>" & $iOffsetStringInString & @cr & $ierrorSave & @CR & $iextendedSave & @CR)
ConsoleWrite(@CR)

Local $iMatchNoMatchIndicator = StringRegExp($sHTML,$sPattern)
$ierrorSave = @error
$iextendedSave = @extended
ConsoleWrite("$iMatchNoMatchIndicator>" & $iMatchNoMatchIndicator & @cr & $ierrorSave & @CR & $iextendedSave &@CR)
ConsoleWrite(@CR)
ConsoleWrite(@CR)



$sPattern = 'eader">Special Circumstances'
ConsoleWrite("...............................$sPattern>" & $sPattern & "<" &  @CR)


$iOffsetStringInString = StringInStr($sHTML,$sPattern)
$ierrorSave = @error
$iextendedSave = @extended
ConsoleWrite("$iOffsetStringInString>" & $iOffsetStringInString & @cr & $ierrorSave & @CR & $iextendedSave & @CR)
ConsoleWrite(@CR)

Local $iMatchNoMatchIndicator = StringRegExp($sHTML,$sPattern)
$ierrorSave = @error
$iextendedSave = @extended
ConsoleWrite("$iMatchNoMatchIndicator>" & $iMatchNoMatchIndicator & @cr & $ierrorSave & @CR & $iextendedSave &@CR)
ConsoleWrite(@CR)
ConsoleWrite(@CR)

output:

Quote

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "R:\Operations\MacroTools\AutoIT\tests\testRegExp.au3" /UserParams    
+>11:12:24 Starting AutoIt3Wrapper v.15.920.938.0 SciTE v.3.6.0.0   Keyboard:00010409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0409)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Pkryder\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Pkryder\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:R:\Operations\MacroTools\AutoIT\tests\testRegExp.au3
+>11:12:24 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "R:\Operations\MacroTools\AutoIT\tests\testRegExp.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop


...............................$sPattern>header">Special Circumstances<
$iOffsetStringInString>17
0
0

$iMatchNoMatchIndicator>0
0
0

...............................$sPattern>eader">Special Circumstances<
$iOffsetStringInString>18
0
0

$iMatchNoMatchIndicator>1
0
0

+>11:12:24 AutoIt3.exe ended.rc:0
+>11:12:24 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.5369
 

 

Share this post


Link to post
Share on other sites



Sorry  for the noise.

I now see the capital letter is not matched in the RegEx.

Sorry. Phil

Share this post


Link to post
Share on other sites

Just incase you need to know how.  Its (?i) before your pattern to make regex case insensitive. 

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