Free tool
Python Regex Tester
Test any with Python's own re module, right in your browser. 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 Python's own re module, in your browser, and you see every match and its groups.
Result
Getting Python ready in your browser; this only happens once…
Pattern explained
/product/the text "/product/" as it is(?P<id>start of group id, which keeps what it matches under that name\done digit, Arabic-Indic digits like ٣ included+the part before appears once or more)end of the group
Regex rules in Python
Use raw strings
Put r before the quotes, as in
r"\d+". Without it, Python turns\binto a backspace character before re ever sees it, and the pattern matches nothing.search, match and fullmatch
re.searchfinds the pattern anywhere,re.matchonly at the start, andre.fullmatchonly when it covers the whole string.re.finditerreturns every match, and it's what this tester shows.It's case-sensitiveSEOandseoare different unless you addre.IGNORECASEor start the pattern with(?i).It knows Arabic
\wmatches Arabic letters,\dmatches Arabic digits like ١٥, and\bfinds Arabic word boundaries, unlike Search Console and JavaScript. re has no\p{Arabic}, though: use[\u0600-\u06FF]instead.
Source: Python's re documentation
Regex cheat sheet
Click any example to try it in the tester.
^- Start of the text
$- End of the text
|- Or
( )- Group
(?P<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, Arabic digits too
\wA letter, digit or _, in any script\b- A word boundary, in any script
\s- A space
[\u0600-\u06FF]- An Arabic letter
(?<=…)- Preceded by, without matching it
(?i)- Case-insensitive
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.
Python regex FAQ
How do I test a regex in Python?
Type the pattern and paste the text you're searching: you see every match with its groups and position, because the tester runs Python's own re module in your browser. Then use the pattern in your code, for example re.findall(r"\d+", text).
What's the difference between re.search, re.match and re.findall?
What's the difference between re.search, re.match and re.findall?re.search returns the first match anywhere in the string, re.match returns a match only if the string starts with it, and re.findall returns a list of every match. If the pattern has one group, re.findall returns only what that group matched, so re.findall(r"/product/(\d+)", text) gives you just the product IDs.
Why do I need the r before a Python regex?
Python reads the backslashes in a normal string before re does, so "\b" becomes a backspace character and the pattern matches nothing. In a raw string, r"\b", the backslash reaches re untouched, so write every regex as a raw string.
How do I match Arabic text with Python regex?
Python handles Arabic out of the box: \w matches Arabic letters and \b finds Arabic word boundaries, so \bسعر\b matches the word سعر but not سعرات. To match Arabic letters only, use [\u0600-\u06FF], because re doesn't support \p{Arabic}.
Is Python regex different from Search Console regex?
The basics are the same, but Python supports lookaheads, lookbehinds and backreferences, it's case-sensitive, and it knows Arabic word boundaries. 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.