Opened 10 years ago

Closed 10 years ago

#2460 closed Bug (Fixed)

_StringBetween bug when $sStart = $sEnd

Reported by: jchd18 Owned by: Jpm
Milestone: Component: Standard UDFs
Version: Severity: None
Keywords: Cc:


Local $aRes = _StringBetween("abbbaccca", "a", "a")
; "bbb" is between "a" and "a" and is returned OK
; "ccc" is also between "a" and "a" but is not returned _ArrayDisplay($aRes)

I propose the following change to fix this case:

Local $aRes = _StringBetween("abbbaccca", "a", "a")
; "bbb" is between "a" and "a"
; "ccc" is also between "a" and "a" and is now returned

; #FUNCTION# ====================================================================================================================
; Author ........: SmOke_N (Thanks to Valik for helping with the new StringRegExp (?s)(?i) issue)
; Modified.......: SmOke_N - (Re-write for speed and accuracy), jchd
; ===============================================================================================================================
Func _StringBetween($sString, $sStart, $sEnd, $fCase = Default)
	Local $sCase = "(?" & ($fCase ? "i" : "") & "s)"

	; If you want data from beginning then replace blank start with beginning of string
	$sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"

	; If you want data from a start to an end then replace blank with end of string
	$sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"

	Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3)
	If @error Then Return SetError(1, 0, 0)
	Return $aReturn
EndFunc   ;==>_StringBetween

Attachments (0)

Change History (1)

comment:1 Changed 10 years ago by Jpm

  • Milestone set to
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [9009] in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Jpm.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.