Gauging Interest in Enhanced JavaScript Regex Methods

Update: Some of the functionality discussed here has made its way into later versions of XRegExp.

So, I'll admit that XRegExp 0.1, though hopefully interesting or useful for some people, was scaled back from my original plans. There were two reasons for this:

  1. To get it out the door.
  2. Aside from from a few marginally useful syntax constructs, I'd already included all standard regular expression features which I could think of ways to mimic while still allowing the constructed regular expression objects to be used with built-in JavaScript regex methods without any changes to expected behavior (e.g., backreference ordering).

However, if I don't worry about the regexes being used with built-in methods, and instead create custom methods (possibly with names like xmatch, xreplace, xexec, etc.), a number of significant, additional features become technically possible to mimic. Things like atomic groups, possessive quantifiers, named capture, and even infinite-length lookbehinds (though lookbehinds would have to be limited to appearing at the start and/or end of regexes, or alternatively not be used together with lookaheads).

However, since some of this stuff might be tricky to pull off, and I'm not really sure how useful most people would find this, or if the majority of people prefer regex literals over a constructor even given the feature enhancements possible through a custom constructor, I'd like to gauge interest in this stuff before thinking much more about it. Do you think you would regularly use the features I mentioned, even given that it would require the use of a custom constructor and methods? Do you use regular expressions in JavaScript but don't see yourself including a script just so you can do this stuff? Do you think the convenience of regex literals outweighs the benefits of enhanced syntax? Let me know. If you'd like more details, wanna help out with this, or have any other comments, I'd be happy to hear from you, as well.

4 thoughts on “Gauging Interest in Enhanced JavaScript Regex Methods”

  1. Boyan, I tend to agree with your take on this (i.e., not working on it until there’s a need). However, it’s pretty unlikely I’ll ever run into a personal need, since manually mimicking features on a case-by-case basis is generally a lot easier up front than automating the process.

    As for Cruiser, yeah, it’s interesting. I actually saw it a few days ago on Ajaxian, and I’ve left several comments on the page you linked to (although my regexes in the first comment there are missing a bunch of characters due to the Textile auto-formatting in place).

  2. Is there any function which allows you to find out if a string is a valid prefix of a regex and what the valid lookahead characters are after the prefix? My use is in validating form input fields: after a new character is added to the field, run the field contents through the field’s validation regex. If the character causes the regex to fail, then remove the character from the field. Additionally, if the field has only one valid lookahead character, add that lookahead to the field.

    For example, validate a telephone number and automatically fill in the dashes (‘-‘).


Leave a Reply

Your email address will not be published. Required fields are marked *