Flagrant Badassery

A JavaScript and regular expression centric blog

RegexPal: Web-Based Regex Testing Reinvented

Yes I know, there are many other JavaScript regex testers available. Why did I create yet another? RegexPal brings several new things to the table for such web-based apps, and in my (biased) opinion it's easier to use and more helpful towards learning regular expressions than the others currently available. Additionally, most other such tools are very slow for the kind of data I often work with. They might appear fast when displaying 10 matches, but what about 100, 1000, or 5000? Try generating 5,000 matches (which is easy to do with an any-character pattern such as a dot) in your favorite existing web-based tool and see if your browser ever recovers (doubtful). The same task takes RegexPal less than half a second, and what's more, results overlay the text while you're typing it.

At the moment, RegexPal is short on features, but here are the highlights:

  • Real-time regex syntax highlighting with backwards and forwards context awareness.
  • Lightning-fast match highlighting with alternating styles.
  • Inverted matches (match any text not matched by the regex).
regexpal.com screenshot

I'm not sure when I'll add additional features, but there are lots of things I'm considering. If there is something you'd like to see, let me know.

A few things to be aware of:

  • The approach I've used for scrollable rich-text editing (which I haven't seen elsewhere) is fast but a bit buggy. Firefox 2 and IE7 have the least issues, but it more or less works in other browsers as well.
  • The syntax highlighting generally marks corner-case issues that create cross-browser inconsistencies as errors even if they are the result of browser bugs or missing behavior documentation in ECMA-262 v3.
  • There are different forms of line breaks cross-platform/browser. E.g., Firefox uses \n even on Windows where nearly all programs use \r\n. This can affect the results of certain regexes.

At least for me, RegexPal is lots of fun to play with and helps to make learning regular expressions easy through its instant feedback. I encourage you to just go play with it and discover its results on your own, but for the curious, I'll keep rambling…

Regex syntax parsing (needed for the syntax highlighting) is somewhat complex, due to the numerous backwards and forwards context awareness issues involved. Take, for example, the pattern \10. What does it mean?

  • Backreference 10, if not inside a character class and at least 10 capturing groups are opened before that point.
  • Backreference 1, followed by a literal "0", if not inside a character class and between 1 and 9 capturing groups are opened before that point.
  • Octal character index 10 (decimal 8), if inside a character class, or if no capturing groups are opened before that point.
  • The three literal characters "\", "1", and "0", if preceded by an unescaped "\" character.
  • An incomplete token in a couple other situations.

Another example is the "-" character. Outside a character class it's always a literal hyphen, but inside a character class…

  • It creates a range between tokens if:
    • There is a preceding and following token in the class, or it's preceded by a token and is the last character in an unclosed character class (caveats follow).
  • It's a literal character if:
    • It's the first or last character in the class.
    • It's preceded by an unescaped "\".
    • It follows a token which is the end index for a range.
    • It follows a hyphen which creates a range.
  • It's an error if:
    • It's creating a range between tokens in reverse character index order (e.g., z-a, @-!, \uFFFF-\b, or \127-\cB).
    • It would otherwise create a range, but it's followed or preceded by a token which represents more than one character index (e.g., \d). In fact, in some cases browsers take this to mean that the hyphen should be treated as a literal, but browser bugs cause it to be handled inconsistently so RegexPal flags it as a range error.

Here are a few more things which aren't errors but are flagged as such:

  • Empty, top-level alternation, except at the end of the pattern, where such an alternation is ignored when highlighting matches in order to create a less surprising experience while the user is in the middle of constructing the regex. Empty, top-level alternation is flagged as an error because it effectively truncates the regex at that point (since it will always match). If a zero-length, top-level alteration is really needed, there are other easy ways to do that more explicitly.
  • Lookaround quantifiers (e.g., the plus sign in (?!x)+). This would be an actual error with some regex libraries (e.g., PCRE), and although that's not the case in most web browsers, such constructs add no value. As a result, RegexPal flags such quantifiers as an error, since they are almost certainly a user mistake.
  • \c when not followed by A–Z, \x when not followed by two hex characters, and \u when not followed by four hex characters. Although these do not cause most browsers to throw errors, they are handled inconsistently cross-browser and are hence flagged as errors. They would almost certainly be a user mistake even if the cross-browser issues didn't exist.

Credit to osteele.com from where the text of the short-and-sweet Quick Reference is based, and to RegexBuddy from JGsoft for inspiring many of RegexPal's features. The name RegexPal is, in part, a nod to RegexBuddy, but also selected because it contains both "regex" and "regexp." wink

There Are 70 Responses So Far. »

  1. You know what’s funny? I came upon RegexPal today in my Programming RSS feed and before the link was open I came here to see what you had to say about it. It turns out you made it! Your intense passion for and knowledge of regexes is so profound that now whenever I think of regex, I think of this site. Well done, sir.

  2. Steve is a master of Regexery. Nevertheless, whenever I think of having too much time on my hands, I think of this site.

  3. Nicely done, Steve. You might be the only person I know who loves regex more than I do.

  4. I just found myself having to write a regex for work, and suddenly I remembered Ryan mentioning RegexPal to me a few weeks ago. I tried it out and it works like a charm. Nicely done, sir.

  5. Fantastic tool and I agree; much easier to use than any other I’ve found. One quick question – is it possible to tell it to search over the end of lines? I’ve been building a suite of regexes to parse c++ headers to retrieve the public interfaces. It would have been nice to be able to highlight properly the following matched comment:

    /* some multiline comment
    which my software is able to strip
    with the regex your site helped me build :-) */

    The regex your tool helped me build worked, but it would be even better still if there was a “Treat multiline input as a single string” option.

    One other enhancement that would be fantastic would be the ability to pipe one regex output into a second edit box and perform another regex on that. Add that and you’ve got a very powerful tool to build multi-level regexes …and I would be a very grateful little developer! ;-)

  6. Ooops.. I just realised you can do the multiline thing with the “Dot matches all” option! :)

  7. The problem with using visual tools to justify something capable of matching invisible items… what happens when you want to test the matching of invisible items with a visual tool (highlighting)?

  8. Hi, I also posted about the linebreak issue earlier. I recommend having a ‘show all characters’ or ‘show invisible character highlights’ option to remedy that.
    Also I noticed this ‘bug’ in the wordwrap behavior of textarea, you can see it here:

  9. A great addition would be a little notification of the milliseconds or microseconds it took to find all the matches within the haystack. The speed of different regex patterns is something I always want to test as well.

  10. I find your testers by google and it’s very useful!
    I’m French and I will give the URL at all of my friends!
    Thank you very much!

  11. Before anything else, a million thanks to Steve for this great tool for webdevs all over the world!

    I was trying out lookbehind (?<=) and found that it did not work even though that lookahead works normally. Anyone else having this problem?

    Furthermore, I’ve been wondering about the various colors used in the regexpal application. I know for certain that yellow highlight is for positive results, but I haven’t figured out what blue highlights do at the time being.

  12. Thanks for the suggestions, bug reports, and compliments, everyone.

    @k4emic, JavaScript doesn’t support lookbehind, so RegexPal correctly highlights your group as an error (red). As for the highlighting of match results, they simply alternate between yellow and blue. This allows you to easily determine where one match ends and the next begins, even when two matches are adjacent to each other.

  13. Whoa!
    You did a great job!
    Thank you!

  14. You have a great online tester there. I love that it not only highlights matches – but different sets of matches are different colors! Forget the stuff I was using – your site is now my new tester!

  15. Couldn’t get it to work, nothing in my test data would highlight (though my source regex would). I think it would be much more useful if on page load it was populated with an example.

  16. I LOVE YOUR REGEX TESTER. It has some highlighting issues in FF but works correctly with IE. I’ve only experienced the highlighting issue once though, the highlight was shifted. It worked fine in IE though. If I can find the regex and data ill be sure to post it for you! THANK AGAIN!

  17. Thank you for your great tool!!!
    I only would add a message indicating that yellow colour means a match with the expression.

  18. Great tool!

  19. I’m enthused! That is what I’ve always been looking for.

  20. How to insert it on $(document.body).text() to find texts with a regular expression?

  21. Hey man, I have a suggestion for this wonderful tool.

    What do you think of the groups highlight the text with regexp in the same colors!?


  22. Guess I am stupid . . . So, when I enter my pattern and then my test data what do I do next? I have no idea how to tell it “GO!”

  23. @Confused, it goes automatically. See http://bit.ly/c9gmZw for an example of how matches are highlighted. If you’re not seeing any matches, most likely that means your regex doesn’t match within your target text.

  24. If you paste a regular expression in first and then paste test data in second it does nothing. You must modify the regular expression in order to get it to “GO.” Trivial enough once you realize that’s the trick but initially confusing.

  25. Not sure what all the colours about?
    I’ve been using http://www.regexr.com so far

  26. Is there a way to copy the matched result to clipboard?

  27. What does yellow mean, and what does blue mean? A legend would be helpful. Cool site tho.

  28. Nice Editor saves my time thank you.

  29. This tool will really reduce my trial and error time when writing regular expressions. This tool is totally awesome! Thanks for your work.

  30. A great addition would be a little notification of the milliseconds or microseconds it took to find all the matches within the haystack. The speed of different regex patterns is something I always want to test as well.

  31. Since your site is meant for people trying to learn RegEx it’d be great if you could include a legend to inform us what the different colors mean.

  32. Great tool. Thank you for making it. I agree with others that the alternating color thing is confusing initially, since there is no legend.

  33. I have heard from several others that this is really useful but they already had a decent grasp on regex. I don’t really understand regex at all though I have stumbled through making it work a few times. Anyway, I have tried to figure out how this thing works and have pretty much failed to get the point of what it is doing. Maybe having a few quick examples of how to use it would help.

  34. Looks like highlighting is broken. After typing my first non-matching line (I had ‘m’ and ‘s’ on), every new line I enter is highlighted whether matching or not, and all the same color.

  35. Thank you! Despite there are many regex testers around, yours is the best!

  36. Yep…sadly nothing is highlighted anymore.
    Broken web app,
    with no support or answer from author
    …abandoned app?

    Using Firefox 16.02
    XP-PRO SP3

  37. @SFtest, RegexPal hasn’t been updated in a while, but it’s not abandoned. I just tested it in Firefox 15 and 17 (16 not immediately available), Chrome 23, and IE 9. It’s working fine in all of them.

    For people wondering about the alternating match colors, there is no difference between yellow and blue matches. The colors alternate simply so that you can tell where one match ends and the next match starts, when they are directly adjacent. (Previously mentioned in this comment.)

  38. You should add (?P) syntax to the site.
    http://php.net/manual/en/function.preg-match.php (see example #3)

  39. I also haven’t had any trouble with running RegExPal, and I think it’s a great tool. I do have a feature request – it would be even more useful if it incorporated the look-behind scripts you posted separately. As it is I’m finding it difficult to get my head around exactly what they’re doing.

  40. Hi – I love and use RegexPal frequently, but the site appears to be down. Is it down for good, for maintenance, etc?

    Thanks for this excellent tool!


  41. @Aron, I was having hosting issues for a couple days, but the site is back up. :)

  42. Fantastic tool! Love it very much. Easy to use and powerfull. It saved my life for a couple of times when we need fast solutions for sorting data-textfiles.
    But with bigger files (>150KB) it seems to slow down and freeze, or is it my browser (Fiefox)?

  43. RegexPal,RegexBuddy are really nice tools!!

  44. Can some one help me in writing the regexp to ignore a particular set of digits??

  45. Does the http://regexpal.com/ site not work with Unicode flags or am I doing something wrong? If I use this regex string \\p{L}+ and test against this string ??? it fails.

    PS: Thank you for all your hard work and open contributions Steve.

  46. Previous comment contained a small Japanese phrase but looks like this form doesn’t support Unicode at this time.

  47. I always spent my half an hour to read this website’s articles or reviews all the time along
    with a cup of coffee.

  48. I am in fact delighted to read this webpage posts which includes plenty of useful facts,
    thanks for providing such statistics.

  49. Hi, i think that i saw you visited my weblog
    thus i came to “return the favor”.I am attempting to find things to enhance my site!I suppose
    its ok to use a few of your ideas!!

  50. Commuter students also lose out on the opportunity to leave the house and forge some independence.
    c) Improvement : With practice the child who is ready to learn
    will show the improvement-even if only slight and gradual.

    An Authorized Institution that Aims to Deliver the Best.

  51. Hi there very nice site!! Guy .. Excellent .. Superb ..
    I’ll bookmark your blog and take the feeds also? I am satisfied to seek out numerous useful information here within the
    publish, we’d like work out extra techniques in this regard,
    thank you for sharing. . . . . .

  52. I’m curious to find out what blog platform you’re working with?
    I’m having some minor security issues with my latest site and I would like to find something more safe.
    Do you have any solutions?

  53. Hell?, I enjoy reading through yo?r article post. I wanted to
    write a little comment to supp?rt you.

  54. Hi, the whole thing is going perfectly here and ofcourse every one is sharing data, that’s in fact excellent,
    keep up writing.

  55. I am genuinely delighted to read this weblog posts which carries
    plenty of valuable facts, thanks for providing these data.

  56. I don’t know if it’s just me or if perhaps everyone else encountering problems with your site.

    It looks like some of the text in your content are running off
    the screen. Can somebody else please comment and let me know if this is happening to them as
    well? This may be a issue with my web browser because I’ve had this happen previously.
    Appreciate it

  57. Excellent site. A lot of useful information here. I’m sending
    it to several buddies ans also sharing in delicious. And obviously,
    thanks in your effort!

  58. It’s really a cool and helpful piece of info. I am
    glad that you just shared this useful information with us.

    Please stay us informed like this. Thank you for sharing.

  59. I have fun with, result in I discovered exactly what I was taking a look for.

    You have ended my 4 day lengthy hunt! God Bless
    you man. Have a great day. Bye

  60. I like the valuable info you provide on your articles.
    I will bookmark your weblog and check again right here
    frequently. I am fairly certain I’ll be told many new
    stuff proper here! Good luck for the next!

  61. I do not even understand how I stopped up here, however
    I believed this put up used to be good. I do
    not recognise who you might be but definitely you are going to a well-known blogger in case you are not already.

  62. Attractive section of content. I simply stumbled upon your weblog and in accession capital to claim that I get actually
    loved account your weblog posts. Any way I’ll be
    subscribing to your augment and even I success
    you get admission to consistently fast.

  63. excellent publish, very informative. I’m wondering why the other
    experts of this sector don’t notice this. You should continue your writing.
    I’m sure, you have a huge readers’ base already!

  64. I create a leave a response when I like a post on
    a site or if I have something to contribute to the conversation.
    Usually it’s triggered by the passion communicated in the
    article I browsed. And after this article Flagrant
    BadasseryRegexPal: Web-Based Regex Testing Reinvented.
    I was excited enough to post a thought :) I do have
    a few questions for you if it’s okay. Could it be only me or do some
    of these comments appear as if they are left by
    brain dead individuals? :-P And, if you are writing at additional places, I’d like
    to keep up with everything new you have to post.
    Could you make a list the complete urls of all your public pages like your Facebook page, twitter feed, or
    linkedin profile?

  65. Hi! I realize this is sort of off-topic however I needed
    to ask. Does managing a well-established blog such as yours take a lot of
    work? I am completely new to writing a blog however I do write in my diary
    every day. I’d like to start a blog so I can easily share my personal experience and views online.
    Please let me know if you have any recommendations or
    tips for new aspiring bloggers. Appreciate it!

  66. Hello, i believe that i noticed you visited my website thus i got
    here to return the prefer?.I am attempting to to find issues
    to enhance my website!I assume its adequate to
    make use of a few of your ideas!!

  67. I am really enjoying the theme/design of your web site. Do you
    ever run into any browser compatibility problems?
    A number of my blog audience have complained about my
    website not working correctly in Explorer but looks great in Chrome.
    Do yoou have any suggestions to help fix this issue?

  68. Thanks in support of sharing such a pleasant thinking,
    paragraph is good, thats why i have read it completely

  69. Love my shoe! Thank you!!!!
    Celine bag Replica http://www.laconduiteenligne.com/Celine/

  70. This is really interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your fantastic post.
    Also, I have shared your web site in my social networks!

Post a Response

If you are about to post code, please escape your HTML entities (&amp;, &gt;, &lt;).