Created
February 7, 2011 14:11
-
-
Save Zoramite/814407 to your computer and use it in GitHub Desktop.
Testing ORO vs custom function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfset testRegex = trim(fileRead('regexString.txt')) /> | |
<cfset testLen = 100000 /> | |
<h1>Testing Regex Escaping</h1> | |
<cfoutput>Using the following regex: #testRegex#</cfoutput> | |
<h2>Perl5Compiler quotemeta</h2> | |
<cfset o = createobject('java', 'org.apache.oro.text.regex.Perl5Compiler', expandPath('./jakarta-oro.jar')) /> | |
<cfoutput>Example output: #o.quotemeta(testRegex)#</cfoutput> | |
<cfset start = getTickCount() /> | |
<cfloop from="1" to="#testLen#" index="i"> | |
<cfset o.quotemeta(testRegex) /> | |
</cfloop> | |
<cfset total = getTickCount() - start /> | |
<cfoutput>Total time for #testLen# quotemeta(): #total# ms</cfoutput> | |
<h2>REEscape</h2> | |
<cfoutput>Example output: #REEscape(testRegex)#</cfoutput> | |
<cfset start = getTickCount() /> | |
<cfloop from="1" to="#testLen#" index="i"> | |
<cfset REEscape(testRegex) /> | |
</cfloop> | |
<cfset total = getTickCount() - start /> | |
<cfoutput>Total time for #testLen# reescape(): #total# ms</cfoutput> | |
<!--- | |
Request for this function: https://issues.jboss.org/browse/RAILO-1168 | |
Code originally from: http://www.railodeveloper.com/post.cfm/regexsafe-function-for-coldfusion | |
Characters escaped in OBD 1.5 BER: $, {, }, (, ), <, >, [, ], ^, ., *, +, ?, #, :, &, and \ | |
---> | |
<cffunction name="REEscape" returntype="string" access="public" output="no" hint="Escapes characters with special meaning for regular expression in a given string"> | |
<cfargument name="text" type="string" required="yes" hint="The string to escape the characters in" /> | |
<cfreturn rereplace(arguments.text, "(?=[\[\]\\^$.|?*+(){}<>##:&\-])", "\", "all") /> | |
</cffunction> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment