Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $s = "bla-F-Ukltr-blub"
- _StringRegExpReplace_Callback($s, "(?i)(.+-)(F|R)(-)(U.+)(-.+)", '_MyFormat("$4")', '$1', '$3$2$5')
- ConsoleWrite($s & @CRLF)
- Func _MyFormat($s)
- Return StringUpper($s)
- EndFunc
- ; #FUNCTION# ====================================================================================================================
- ; Name ..........: _StringRegExpReplace_Callback
- ; Description ...: Replaces ByRef all matches in a string by manipulation of the matches in a callback function
- ; Parameters ....: $sString String to manipulate
- ; ...............: $sPattern RegExp pattern for the match
- ; ...............: $sCallback Callback function as string, i.e. "MyCallback('$1')" -- '$1' represents the match
- ; .....optional..: $sBefore String to insert before the manipulated match
- ; .....optional..: $sAfter String to insert after the manipulated match
- ; Return values .: Success 1
- ; ...............: Failure 0 set error = 1
- ; Author ........: Taz77
- ; ===============================================================================================================================
- Func _StringRegExpReplace_Callback(ByRef $sString, $sPattern, $sCallback, $sBefore = '', $sAfter = '')
- $sString = Execute("'" & StringRegExpReplace(StringReplace($sString, "'", Chr(26), 0, 2), $sPattern, $sBefore & "'&" & $sCallback & "&'" & $sAfter) & "'")
- If @error Then
- ConsoleWrite('_StringRegExpReplace_Callback error! Pattern: "' & $sPattern & '", Callback: "' & $sCallback & '"' & @LF)
- Return SetError(1,0,0)
- EndIf
- $sString = StringReplace($sString, Chr(26), "'", 0, 2)
- Return 1
- EndFunc ;==>_StringRegExpReplace_Callback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement