Sign in to follow this  
Followers 0
DannyDomb

StringRegExpReplace

4 posts in this topic

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 :mellow:

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Malkey

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

thanks guys, i will try this as soon as i return home.

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  
Followers 0