Steveiwonder Posted November 23, 2010 Posted November 23, 2010 (edited) Hey all, I'm a little confused with this one. The below regexp works fine, it displays in the console "James Smith James Brown" $string = "James Smith James Brown" $result = StringRegExp($string, "(?i)James\s\w+\b", 3) if UBound($result) > 0 Then for $r in $result ConsoleWrite($r & @CRLF) Next EndIf however if i want to match either James OR Jamie i get some probems, if i change my regexp to: $result = StringRegExp($string, "(?i)(James|Jamie)\s\w+\b", 3) I just displays "James James" Should it not Match James or Jamie then continue to look for the Surname with the "\s\w+\b" part of the patern? or am i missing something? If i then change the string to: $string = "James Smith Jamie Brown" I just get: "James Jamie" but no surname. Apprciate any input. Thanks. Steve. Edited November 23, 2010 by Steveiwonder They call me MrRegExpMan
MvGulik Posted November 24, 2010 Posted November 24, 2010 (edited) Your running into the problem that your adding a additional next-level capture-group by using '(...)' the way you do.To correct that you need to drop it back to the same level of the rest of your RE-code. This is done by adding a '?:' directly behind the opening of the group. -> '(?:...)'So your final RE should be '(?i)(?:james|jamie)\s\w+\b'See AutoIt 'StringRegExp' help and http://www.regular-expressions.info/ for more RE related information. Edited November 24, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
Steveiwonder Posted November 24, 2010 Author Posted November 24, 2010 (edited) .... Thank you works a treat and thanks for the explanation it makes sense Edited November 24, 2010 by Steveiwonder They call me MrRegExpMan
Jimtags Posted November 24, 2010 Posted November 24, 2010 Hello... I would like to ask regarding StringRegExp My question is.. is't possible to get the count of same letters of two variables? for example $var1 = "Jimmy" $var2 = "Maika" as you can see $var1 got 3 the same letters to $var2.. and $var2 got 2 the same letters to $var1 i want to get the count of the same letters on each variable ... just like the game FLAMES. --im waiting for any reply!.. Thanks
Moderators SmOke_N Posted November 24, 2010 Moderators Posted November 24, 2010 Hello... I would like to ask regarding StringRegExp My question is.. is't possible to get the count of same letters of two variables? for example $var1 = "Jimmy" $var2 = "Maika" as you can see $var1 got 3 the same letters to $var2.. and $var2 got 2 the same letters to $var1 i want to get the count of the same letters on each variable ... just like the game FLAMES. --im waiting for any reply!.. Thanks Not without writing the correct pattern! Anyway: #include <Array.au3> Global $svar1 = "Jimmy" Global $svar2 = "Maika" Global $icount1 = _MyGetCharCount($svar1, $svar2) ConsoleWrite("Count: " & $svar1 & " has " & $icount1 & " of the same characters as " & $svar2 & @CRLF) Global $icount2 = _MyGetCharCount($svar2, $svar1) ConsoleWrite("Count: " & $svar2 & " has " & $icount2 & " of the same characters as " & $svar1 & @CRLF) Func _MyGetCharCount($s_var1, $s_var2, $v_case = 0) Local $a_split = StringSplit($s_var2, "", 2) Local $a_unique = _ArrayUnique($a_split) Local $s_pattern = _ArrayToString($a_unique) If Not $v_case Then $s_pattern = "(?i)" & $s_pattern StringRegExpReplace($s_var1, $s_pattern, "") Return @extended EndFuncShould obtain what you want Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Jimtags Posted November 24, 2010 Posted November 24, 2010 (edited) Owww... It really help... thanks a lot! Edited November 24, 2010 by Jimtags
MvGulik Posted November 24, 2010 Posted November 24, 2010 (edited) No completely sure. But,; (code-tag bug workaround) Local $s_pattern = '[' & $s_var2 & ']'seem equivalent to,; (code-tag bug workaround) Local $a_split = StringSplit($s_var2, "", 3) Local $a_unique = _ArrayUnique($a_split) Local $s_pattern = _ArrayToString($a_unique)in its behavior.(edits: done) Edited November 24, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
Moderators SmOke_N Posted November 24, 2010 Moderators Posted November 24, 2010 No completely sure. But,; (code-tag bug workaround) Local $s_pattern = '[' & $s_var2 & ']'seem equivalent to,; (code-tag bug workaround) Local $a_split = StringSplit($s_var2, "", 3) Local $a_unique = _ArrayUnique($a_split) Local $s_pattern = _ArrayToString($a_unique)in its behavior. (edits: done) Mo betta, didn't really take the time to think it out myself ( more time than the op but not enough obviously ). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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