Jump to content
Sign in to follow this  
fmen

Another n00b StringRegExp question

Recommended Posts

fmen

Sorry look stupid but I have tried every combination I can think of, tried to read the StringRegExp help file and example and searched the forum for the last day without success.

I would like to get the position of the last "A" in the string by reading from the end. How do I combine \z and [A] or \D or [:upper:] to achieve it?

Thanks.

Dim $Str = 'opiBjoiAj3t_0ek *_$#^_dkodSAdokd'

Dim $Arr = StringRegExp($Str, '\z', 1) ;gets the last position of the string  (\z Match only at end of string.)
Dim $Arr = StringRegExp($Str, '[A]', 1) ; gets the first "A" 's position in the string
Dim $Arr = StringRegExp($Str, '\z[A]', 1) ; gets buppkiss

MsgBox(0x40, 'Title', 'On position: ' & @extended-1)
Edited by fmen

Share this post


Link to post
Share on other sites
Spiff59

Don't know if this search goes from left to right, or right to left, but gets the desired result:

Dim $Arr = StringRegExp($Str, '.+A', 1)

typo

Edited by Spiff59

Share this post


Link to post
Share on other sites
Malkey

Sorry look stupid but I have tried every combination I can think of, tried to read the StringRegExp help file and example and searched the forum for the last day without success.

I would like to get the position of the last "A" in the string by reading from the end. How do I combine \z and [A] or \D or [:upper:] to achieve it?

Thanks.

Dim $Str = 'opiBjoiAj3t_0ek *_$#^_dkodSAdokd'

Dim $Arr = StringRegExp($Str, '\z', 1);gets the last position of the string  (\z Match only at end of string.)
Dim $Arr = StringRegExp($Str, '[A]', 1); gets the first "A" 's position in the string
Dim $Arr = StringRegExp($Str, '\z[A]', 1); gets buppkiss

MsgBox(0x40, 'Title', 'On position: ' & @extended-1)
Here is an example of Spiff59's suggestion, and a way to find the last "A" position with StringInStr(). Both return the correct result.

Dim $Str = 'opiBjoiAj3t_0eAk *_$#^_dkodSAdokd'

;Find position of last "A"
Dim $Arr = StringRegExp($Str, '.+A', 1)
Local $iRegExp = @extended - 1

Local $iStrInStr = StringInStr($Str, 'A', 1, -1)

MsgBox(0, 'Results', 'RegExp     : ' & $iRegExp & @CRLF & _
                     'StringInStr: ' & $iStrInStr)
Edited by Malkey

Share this post


Link to post
Share on other sites
fmen

Thank you to both.

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  

×