Advertisement
BugFix

_StringRegExCallback

Jan 23rd, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.64 KB | None | 0 0
  1. $s = "bla-F-Ukltr-blub"
  2.  
  3. _StringRegExpReplace_Callback($s, "(?i)(.+-)(F|R)(-)(U.+)(-.+)", '_MyFormat("$4")', '$1', '$3$2$5')
  4. ConsoleWrite($s & @CRLF)
  5.  
  6. Func _MyFormat($s)
  7.     Return StringUpper($s)
  8. EndFunc
  9.  
  10.  
  11. ; #FUNCTION# ====================================================================================================================
  12. ; Name ..........: _StringRegExpReplace_Callback
  13. ; Description ...: Replaces ByRef all matches in a string by manipulation of the matches in a callback function
  14. ; Parameters ....: $sString    String to manipulate
  15. ; ...............: $sPattern   RegExp pattern for the match
  16. ; ...............: $sCallback  Callback function as string, i.e. "MyCallback('$1')" -- '$1' represents the match
  17. ; .....optional..: $sBefore    String to insert before the manipulated match
  18. ; .....optional..: $sAfter     String to insert after the manipulated match
  19. ; Return values .: Success     1
  20. ; ...............: Failure     0  set error = 1
  21. ; Author ........: Taz77
  22. ; ===============================================================================================================================
  23. Func _StringRegExpReplace_Callback(ByRef $sString, $sPattern, $sCallback, $sBefore = '', $sAfter = '')
  24.     $sString = Execute("'" & StringRegExpReplace(StringReplace($sString, "'", Chr(26), 0, 2), $sPattern, $sBefore & "'&" & $sCallback & "&'" & $sAfter) & "'")
  25.     If @error Then
  26.         ConsoleWrite('_StringRegExpReplace_Callback error! Pattern: "' & $sPattern & '", Callback: "' & $sCallback & '"' & @LF)
  27.         Return SetError(1,0,0)
  28.     EndIf
  29.     $sString = StringReplace($sString, Chr(26), "'", 0, 2)
  30.     Return 1
  31. EndFunc  ;==>_StringRegExpReplace_Callback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement