Free tool
JavaScript Regex Tester
Test any with your browser's own JavaScript engine. You see every match and its groups as you type, with every part of the pattern explained.
Test the pattern as it runs in
The pattern runs with your browser's JavaScript engine, and you see every match and its groups.
Result
Pattern explained
/product/the text "/product/" as it is(start of group 1, which keeps what it matches\done digit, 0 to 9+the part before appears once or more)end of the group
Regex rules in JavaScript
Flags go after the pattern
You write the pattern between slashes and the flags after it, as in
/seo/gi:gfinds every match andiignores case. JavaScript doesn't accept(?i)at the start of a pattern.Word characters are English only
\wonly covers English letters, digits and_, so\bcan't find where an Arabic word starts and\ddoesn't match Arabic digits like١٥. Use(^|\s)before the word and(\s|$)after it instead.Arabic letters need the u flag
\p{Script=Arabic}matches any Arabic letter, but only with theuflag. Without it, the engine reads\pas a plain p and the pattern matches nothing.Lookbehinds and named groups work
Write a named group as
(?<id>\d+)and read it frommatch.groups.id. Lookaheads and lookbehinds of any length work too, like(?<=price\s+)\d+, and Search Console rejects both.
Regex cheat sheet
Click any example to try it in the tester.
^- Start of the text
$- End of the text
|- Or
( )- Group
(?<name>…)- A named group
.- Any one character
*- Any number of times, or none
+- Once or more
?- Optional
{4,}- 4 times or more
[ ]- One character from a set
[^ ]- One character not in the set
\d- A digit, 0 to 9
\wAn English letter, digit or _\b- An English word boundary
\s- A space
\p{Script=Arabic}- An Arabic letter, with u
(?<=…)- Preceded by, without matching it
Free course
Learn Regex for Search Console, step by step
Ten lessons that start with the first pattern you write and end with a full analysis of an online store's data, each with exercises you try in your browser.
JavaScript regex FAQ
How do I test a regex in JavaScript?
Type the pattern, pick the flags and paste your text: you see every match with its groups, because the tester runs the pattern in your browser's own JavaScript engine. Then use it in your code, for example text.match(/\d+/g).
What does the g flag do?
g makes the pattern find every match instead of the first one, so text.match(/seo/g) returns every time the word appears. Watch out with test(): with g it remembers where the last match ended, so calling it twice on the same text can return false the second time.
How do I match Arabic text in JavaScript regex?
Use \p{Script=Arabic} with the u flag, as in /^[\p{Script=Arabic}\s]+$/u, which matches text that's all Arabic. Don't rely on \w or \b: they only know English letters.
Why doesn't my regex match Arabic words in JavaScript?
Why doesn't my regex match Arabic words in JavaScript?Because \w and \b only know English letters, digits and _, even with the u flag, so /\bسعر\b/ finds nothing in سعر القهوة. Write (^|\s)سعر(\s|$) instead.
Is JavaScript regex different from Search Console regex?
The basics are the same, but JavaScript supports lookaheads, lookbehinds and backreferences, and it's case-sensitive unless you add the i flag. Search Console rejects that syntax and ignores case, so if the pattern is for a Search Console filter, test it in the Search Console regex tester.
Does the tester keep the text I test?
No. Testing happens entirely in your browser, and the text is never sent anywhere. Only the description you write for the AI to write a pattern is sent to OpenAI to write it, and we don't keep it.