Regular Expression Testing Tool

  • (blue indicates matches)

Details

This is a JavaScript powered tool that I've created to help myself test out regular expressions. This is only for JavaScript regular expressions since that's what's powering it. Though, most of works here should work in other languages as well. If you've messed with regular expressions the interface should be pretty straight forward. The text field is for your regular expression. Above it are three check boxes that you can set. Global means that the expression will be checked across the whole text rather than just the first occurrence. The second check box will make the expression case insensitive so that 'Good' is seen the same as 'good.' The third check box is for multi-line. This is helpful when using the ^ and $ syntax in a regular expression. The background color on this field will change between two colors. When it's green it means the regular expression is well-formed. When it turns yellow it means it has a typo. When it's yellow the button labeled "Check" above will become active and clicking it will present you with an error about the expression.

The text area below the expression area labeled Test Text is just that, a place to enter some text that you want to test your expression against. Then, below this area is a section that will take the test text and style it to show you what parts were matched. When there is no matches the background color for the test text will turn red. When the background is yellow it means there's a syntax error in the regular expression and any shown matches should not be considered valid. Matched text in the styled output will be colored blue to help tell it apart. There's no button the engage the check, it will update as you type or make changes.

Examples

Here are some examples I have to show you some expressions to try out and use.

Novice

[\w]{4,}
[^\w]{4,}
^[\d\(\)\-]*$

Intermediate

[b-df-hj-np-tv-z]{5,}
<(\/)?[a-zA-Z]+( ([^>]*))*>
^[\w\.\+_\-]+[\w]+@(([\w\-]+)\.)[a-zA-Z]{2,6}$

Advanced

.*(?=.*[A-Z]{2,}.*)(?=.*[a-z]{2,}.*).*
^[a-zA-Z]((?=(.*[a-z].*){2,})(?=(.*[A-Z].*){2,})(?=(.*\d.*){2,})(?=(.*[!&\?#\<\>'].*){2,})(?!.*[$^\*\(\)\+\=\"\.\\\/\|\{\}\[\] \`\~\@])).{7,13}$
(http(s)?\:\/\/)?[\w\.-]+\.[\w]{2,4}(:[\d]{1,5})?(\/([\w\.\/\+\#\~\?\&\=\%-])*)*((\W)+|$)

References / Links