Search the Community
Showing results for tags 'backreference'.
-
BackRef UDF Working This UDF is made to provide a small interface towards the StringRegExpReplace Autoit function. The extension is very limited but is an easy approach when used properly. Functions User can pass the complete back-reference to a function.The return value from the function is then used to replace the specific group.The final replacement is flexible and the user has full control over it.The final replacement is done automatically till modification isn't required.The optimization is easy and simple.LimitationsThe pattern has to consume the full string.Example Replace the vowels with their ASCII code #include <BackRef.au3> $i_BackRef_Debug = True ;Set Debug to true ; .. Example 1 ============================================================================================================================ ; Replace the vowels with their ASCII code Local $Replaced = RegExBackRef( 'Hello Nice Meeting You', '(.*?)([aeiou])(.*)', "AscW" ) ;The Function is inbuilt If @error Then Exit @error MsgBox ( 64, 'Test', $Replaced ) ; ............ ============================================================================================================================ Make the first Number group equal to second number group if its greater than that ; .. Example 2 ============================================================================================================================ ; The Function replaces the first group with third group if its greater than that Local $Replaced = RegExBackRef( '1223 MaxRange : 150', '(\d+)([^:]+:\h+)(\d+)', "SetMaxRange", '\1:\3', "$v & '\2\3'" ) If @error Then Exit @error MsgBox ( 64, 'Test', $Replaced ) ; The User Defined Function Func SetMaxRange( $iString ) $iString = StringSplit( $iString, ':' , 2) $iString[0] = Int ( $iString [0] ) $iString[1] = Int ( $iString [1] ) If $iString[0] > $iString[1] Then Return $iString[1] Return $iString[0] EndFunc ; ............ ============================================================================================================================ The Function replaces unicode chars with ascii alphabet ; .. Example 3 ============================================================================================================================ ; The Function replaces unicode version with ascii alphabet Local $String = 'Déjà' Local $Replaced While 1 $Replaced = RegExBackRef($String, '(.*?)([àâäéèêë])(.*)', "ReplaceFunc") If $Replaced = -1 Or @error Then ExitLoop $String = $Replaced WEnd MsgBox(64, 'Test', $String) Func ReplaceFunc($sMatch) Switch $sMatch Case "é","è","ê","ë" Return "e" Case "à","â","ä" Return "a" EndSwitch EndFunc ;==>ReplaceFunc ; ............ ============================================================================================================================ Convert the unicode lower-case chars to upper-case ; .. Example 4 ============================================================================================================================ ;Convert these chars to upper-case Local $String = "à æ û ü" MsgBox(64, 'Test', GlobalBackRef($String, '(.*?)([\340-\374])(.*)', "ReplaceUniChar")) Func ReplaceUniChar($sMatch) ;Get the ASCII code of the string $iAscW = AscW($sMatch) ;Return the character preceding the current character by 32 Return ChrW($iAscW - 32) EndFunc ;==>ReplaceUniChar ; ............ ============================================================================================================================ ChangeLog v1.0 -First Release v1.1 -Added Debugging features -Added Global Replacement v1.2 -Added Count parameter v1.3 -Now supports formatting control like \r \n and \t in the replace sequence. Download - UDF(v1.3) Here is the UDF to download in the following 7zip file. Please post comments and do give me feedback for improvements and bugs. v1.3 BackRef(UDF).7z Previous Downloads : 44 Regards Phoenix XL