Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; #FUNCTION# ====================================================================================================================
- ; Name...........: _StringBetween
- ; Description ...: Returns the string between the start search string and the end search string.
- ; Syntax.........: _StringBetween($s_String, $s_start, $s_end[, $v_Case = -1])
- ; Parameters ....: $s_String - The string to search.
- ; $s_start - The beginning of the string to find. Passing a blank string starts at the beginning
- ; $s_end - The end of the string to find. Passing a blank string searches from $s_start to end
- ; $v_Case - Optional: Case sensitive search. Default or -1 is not Case sensitive else Case sensitive.
- ; Return values .: Success - A 0 based $array[0] contains the first found string.
- ; Failure - 0
- ; |@Error - 1 = No inbetween string found.
- ; Author ........: SmOke_N (Thanks to Valik for helping with the new StringRegExp (?s)(?i) isssue)
- ; Modified.......: SmOke_N - (Re-write for speed and accuracy)
- ; Remarks .......: 2009/05/03 Script breaking change, removed 5th parameter
- ; Related .......:
- ; Link ..........:
- ; Example .......: Yes
- ; ===============================================================================================================================
- Func _StringBetween($s_String, $s_Start, $s_End, $v_Case = -1)
- ; Set case type
- Local $s_case = ""
- If $v_Case = Default Or $v_Case = -1 Then $s_case = "(?i)"
- ; Escape characters
- Local $s_pattern_escape = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
- $s_Start = StringRegExpReplace($s_Start, $s_pattern_escape, "\\$1")
- $s_End = StringRegExpReplace($s_End, $s_pattern_escape, "\\$1")
- ; If you want data from beginning then replace blank start with beginning of string
- If $s_Start = "" Then $s_Start = "\A"
- ; If you want data from a start to an end then replace blank with end of string
- If $s_End = "" Then $s_End = "\z"
- Local $a_ret = StringRegExp($s_String, "(?s)" & $s_case & $s_Start & "(.*?)" & $s_End, 3)
- If @error Then Return SetError(1, 0, 0)
- Return $a_ret
- EndFunc ;==>_StringBetween
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement