Automating QTP Test Automation Home Automation Articles Downloads QTP Gotchas Links Books Contact About Site Map
String Function - Make Regex SafeWhen converting OR to DP, you have to remember that DP handles regular expressions. Regular expressions are powerful and can be very useful, but in this case they often get in the way. This function makes a string RegEx safe by escaping the characters used. If you find an error, or have a suggestion for improvement, Email me and I'll fix it. Download it Here (right-click and then save target as). (NOTE - you can just cut & paste from below, but the formatting will have multiple spaces instead of tabs). '========================================================================= Function zStr_MakeRegexSafe(sInput) 'DP handles regular expressions 'So "$" is handled as 'Matches the end of input' 'These have to be 'escaped' by prefixing them with a backward slash (\) 'So change all occurences of '$' to "\$" etc. 'Characters to process are.... '$, (, ), *, +, ., [, ?, ^, {, | Dim sOutput sOutput = sInput sOutput = Replace(sOutput, "$", "\$") sOutput = Replace(sOutput, "(", "\(") sOutput = Replace(sOutput, ")", "\)") sOutput = Replace(sOutput, "*", "\*") sOutput = Replace(sOutput, "+", "\+") sOutput = Replace(sOutput, ".", "\.") sOutput = Replace(sOutput, "[", "\[") sOutput = Replace(sOutput, "?", "\?") sOutput = Replace(sOutput, "^", "\^") sOutput = Replace(sOutput, "{", "\{") sOutput = Replace(sOutput, "|", "\|") zStr_MakeRegexSafe = sOutput End Function '========================================================================= |