Online Regex Tester (Perl, PHP, JavaScript)

This form allows you to test regular expressions in Perl, PHP and JavaScript. The form returns the text with all hits highlighted. PHP always finds all matches while Perl or JavaScript consider the existence of the global modifier or its absence respectively. The Perl and PHP scripts are full Unicode capable.Take care: if you are on Windows and hit the line break server-side (Perl, PHP), then you will get two matches because \n on Windows is \r\n on Linux!

Language






Examples of successful matches and error messages as displayed by the form

/[A-Z]/

PHP:

All work and no play makes Jack a dull boy.

Perl:

All work and no play makes Jack a dull boy.

JavaScript:

All work and no play makes Jack a dull boy.

/[a-h]/g

PHP:

preg_replace(): Unknown modifier 'g'

Perl:

That’s one small step for man, onegiant leap for mankind.

JavaScript:

That’s one small step for man, onegiant leap for mankind.

/(?<=\s)[a-z]/

PHP:

To be, or not to be, that is the question:

Perl:

To be, or not to be, that is the question:

JavaScript:

SyntaxError: invalid regexp group

/[a-z]{6,7}(?=\s)/

PHP:

It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.

Perl:

It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.

JavaScript:

It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.

/\w(\w*/

PHP:

preg_replace(): Compilation failed: missing ) at offset 6

Perl:

Unmatched ( in regex; marked by <-- HERE in m/(?)\w( <-- HERE \w*/ at /var/www/xxxxxxx/ingram-braun.net/httpdocs/perl/regex.pl line 39.

JavaScript:

Online Regex Tester (Perl, PHP, JavaScript) 1
SyntaxError: unterminated parenthetical

9 Responses

  1. Useful! I would note that your use of the term “greedy modifier” is technically incorrect; the /g modifier is the GLOBAL modifier, telling the regex to match as many times as possible. Greediness in regex terms refers to how long a continuous match result continues. (+ and * are inherently greedy unless qualified using a question mark.)

  2. Hi, I am having an implementation in Javascript maybe it will be implemented in many languages later. I want to know is there a way to check if the regex in JSON is in Perl or not. And can I convert any Perl regex into ECMA regex?

    • I am not deep enough into regular expressions to provide you with a definite answer here. I have never seen a PCRE2ECMA conversion tool. For a long time, ECMA had less features than PCRE. Don’t know how it is today.

Leave a Reply

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

Post comment