Jump to content

Another n00b StringRegExp question


fmen
 Share

Recommended Posts

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
Link to comment
Share on other sites

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