Jump to content

Recommended Posts

Posted

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:

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

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
×
×
  • Create New...