Created
February 16, 2009 16:45
-
-
Save subtleGradient/65243 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // RegExp.prototype.x= | |
| // var myRegex = /fred/.x(); | |
| // RegExp.fromString(regexString, properties) | |
| // | |
| var RegExpX = function(pattern, flags){ | |
| flags = flags && flags.split('') || [pattern.global?'g':'', pattern.ignoreCase?'i':'', pattern.multiline?'m':'', pattern.extended?'x':''].join(''); | |
| if (flags.indexOf('x')+1) { | |
| flags = flags.replace('x',''); | |
| pattern | |
| } | |
| return new RegExp(pattern, flags); | |
| } | |
| var regexLiteral = /\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g; | |
| var regexConstructed = new RegExp("\\.([\\w-]+)|\\[(\\w+)(?:([!*^$~|]?=)([\"']?)([^\\4]*?)\\4)?\\]|:([\\w-]+)(?:\\([\"']?(.*?)?[\"']?\\)|$)","g"); | |
| document.write(regexLiteral == regexConstructed) | |
| (/fr\ | |
| ed/) | |
| var myRegexX0 = new RegExpX(/flarm/gim,'x'); | |
| var myRegexX1 = /flarm/gim.x(); | |
| var myRegexX2 = RegExpX.from(/flarm/gim); | |
| new RegExpX(/\ | |
| \. ([\w-]+) # className\ | |
| | \[ (\w+) (?: ([!*^$~|]?=) (["']?) ([^\4]*?) \4)? \] # Attribute\ | |
| | : ([\w-]+) (?: \( ["']?(.*?)?["']? \) | $) # Pseudoclass\ | |
| /,"x"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment