DannyDomb Posted August 4, 2011 Share Posted August 4, 2011 Hey, I know it is more a regex question... but could anybody help me? I'm trying to remove everything before a certain string, in a string Exemple String : Hello World, the end is near!!! Search : end return : end is near!!! Thank you very much Link to comment Share on other sites More sharing options...
Malkey Posted August 4, 2011 Share Posted August 4, 2011 (edited) Try this. Local $String = "Hello World, the end is near!!!" Local $Search = "end" ConsoleWrite(StringRegExpReplace($String, "(?is)^(?:.*)(" & $Search & ".*)$", "\1") & @LF) ; or Local $SubStr = StringInStr($String, $Search) ConsoleWrite(StringMid($String, $SubStr, (StringLen($String) - $SubStr + 1)) & @LF) #cs Returns:- end is near!!! end is near!!! #ce Edited August 4, 2011 by Malkey Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 4, 2011 Moderators Share Posted August 4, 2011 (edited) Might want to do something like: Global $gs_Str = "Hello World, the end is near!!!" Global $gs_Find = "End" ; Case sensitive ConsoleWrite(_RemoveToSearchString($gs_Str, $gs_Find, True) & @CRLF) ; case insensitive ConsoleWrite(_RemoveToSearchString($gs_Str, $gs_Find) & @CRLF) Func _RemoveToSearchString($s_str, $s_find, $f_casesensitive = False) Local $s_case = "" If Not $f_casesensitive Then $s_case = "(?i)" Local $s_pattern = $s_case & "^(.*?)(\Q" & $s_find & "\E.*?)\z" Return StringRegExpReplace($s_str, $s_pattern, "$2") EndFunc Notice the \Q and \E Might also look at if it's "words" you're looking for, that the above would not look for word bounds, so if "Send" was before "end", it would remove just past the "S" of "Send". If you need word bounds, replace: Local $s_pattern = $s_case & "^(.*?)(\Q" & $s_find & "\E.*?)\z" With Local $s_pattern = $s_case & "^(.*?)(\b\Q" & $s_find & "\E\b.*?)\z" Edited August 4, 2011 by SmOke_N 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. Link to comment Share on other sites More sharing options...
DannyDomb Posted August 4, 2011 Author Share Posted August 4, 2011 thanks guys, i will try this as soon as i return home. 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