fmen Posted February 9, 2009 Share Posted February 9, 2009 (edited) 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 February 9, 2009 by fmen Link to comment Share on other sites More sharing options...
Spiff59 Posted February 9, 2009 Share Posted February 9, 2009 (edited) 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 February 9, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
Malkey Posted February 9, 2009 Share Posted February 9, 2009 (edited) 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 February 9, 2009 by Malkey Link to comment Share on other sites More sharing options...
fmen Posted February 9, 2009 Author Share Posted February 9, 2009 Thank you to both. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now