Jump to content
Sign in to follow this  

Old StringRegExp

Recommended Posts

I am renewing an older library so that it works with the current.

$iNumChrsToRead = StringRegExp($sParamsInStr, "(\d*?)(\#)(?:\$\[)", 1)
$sParamsInStr = StringTrimLeft($sParamsInStr, $iNumChrsToRead[1])
While StringLen($sParamsInStr) < $iNumChrsToRead[0]

Where $sParamsInStr is equal to "49$[0]$"11111111"$[0]$<nil>$[0]$"2222222"$[0]$<nil>"

I am pretty sure he wants $iNumChrsToRead[1] to be 2

and $iNumChrsToRead[0] to be 49.

What is throwing me off is the use of (\#) .. it seems like at one time would return the length of the first catch. Anyone familar with (\#)

Current AuotIT throws an error because it doesn't find a match to his regex

Share this post

Link to post
Share on other sites

All this "(\#)" means to PCRE is to capture an escaped pound sign as a group.

Are you sure you meant to apply those double quotes that way?

Modify this demo to show the exact value intended for $sParamsInStr, and what you meant to receive in $aNumChrsToRead:

#include <Array.au3>

$sParamsInStr = '"49$[0]$"11111111"$[0]$<nil>$[0]$"2222222"$[0]$<nil>"'
$aNumChrsToRead = StringRegExp($sParamsInStr, "(\d*?)(\#)(?:\$\[)", 1)
If @error Then
    ConsoleWrite("Debug:  @error = " & @error & "; @extended = " & @extended & @LF)
    _ArrayDisplay($aNumChrsToRead, "$aNumChrsToRead")

As is, it gets no matches because there are no literal "#" characters in the string.


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

I had asked about the meaning \# back in 2007. AutoIT forums don't keep that old of history it seems. The double quotes we letting you know it was a string. It doesnt have "" in it. Either way, I just replaced the idea of \# and used StringLen instead.

Share this post

Link to post
Share on other sites

You wouldn't by any chance be thinking of \x## where ## can be 2 hexadecimal digits would you, or even the \### where ### can be up to 3 octal digits?

Literal double quotes can be handles with \x22 for example. As was already ponted out \# just means the literal # symbol.

Edit. For future reference, remember that SRE arrays are 0 based.

$iNumChrsToRead = StringRegExp($sParamsInStr, "(\d*?)(\#)(?:\$\[)", 1);; Return the first match as an array.

will return an array where $iNumChrsToRead[0] will be all digits and $iNumChrsToRead[1] will be the # sign. The expression will not match at a $ symbol followed by a [ symbol

So The type of string it would be looking for would be


Where element 0 is 123456

and element 1 is #

and the # symbol must be followed by $[ in the original string

Edited by GEOSoft


Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver: - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...