A regular expression that “worked on one example” is one of the more expensive kinds of almost-right. It accepts ali@gmail.com, then silently fails a plus-tag, a hyphen in the domain, or a Pakistani mobile number written with spaces. The cheap habit is to try the pattern against a messy block of real text before you paste it into code.
What the tester shows you
The Regex Tester on ToolSphare has a Regular expression field, a Test string box, three flags, a Test Regex button, then Matches and a Highlighted result.
The flags are the familiar JavaScript-style trio:
- Global (g) — find every match, not only the first
- Ignore case (i)
- Multiline (m) — so
^and$can match at line ends, not only at the start and end of the whole string
The pattern placeholder is an email-like example: \b\w+@\w+\.\w+\b. That is a reasonable demonstration and a poor production email validator, which is a useful lesson in itself. \w+ does not know about plus-tags or all valid domains. Use the tester to see what your pattern actually matches, not to assume a famous-looking regex is complete.
There is no sign-up. You paste a pattern, paste text, test, and read the highlights.
How to use it
- Open the Regex Tester workspace.
- Enter the pattern without surrounding slashes unless you intend those slashes to be part of the text (in this box, the pattern and the flags are separate).
- Tick g, i and m as needed. If you only need the first match, leave g off and notice what that does.
- Paste a test string that includes both cases you want to accept and cases you want to reject.
- Click Test Regex. Read Matches and the highlighted result. Adjust the pattern, then test again with the same text.
A practical example: emails and phone numbers in one sample
Suppose a form should catch email addresses and 11-digit Pakistani mobile numbers written as 03xxxxxxxxx. Put this in the test box:
Write to ayesha@example.com or AYSHA@Example.COM. Also try 03001234567 and 0300 1234567 and +92 3001234567. Skip the office line 051-1234567. A first email pattern like \b\w+@\w+\.\w+\b will highlight ayesha@example.com. Turn on Ignore case (i) and Global (g) and check whether the second address is also found. Then look at what you missed: plus-tags, subdomains, or unusual TLDs will need a more careful pattern — or, often, a real email-validation library instead of a harder regex.
For the mobile numbers, try something narrow, for example 03\d{9}, with g on. You should highlight 03001234567 and not the landline. You will also not match 0300 1234567 or +92 3001234567 unless you extend the pattern to allow a space or a +92 prefix. That is the point of the sample: decide which formats you officially accept, write them into the test string, and do not claim the form accepts “any Pakistani number” if you only matched one shape.
A second, slightly different job is extracting capture groups (the bits in parentheses). If this tester’s Matches list shows the full match only, you may still need your unit tests to assert on groups. The on-page contract is: pattern, flags, test string, matches, highlighted result.
Habits that keep regexes boring (in a good way)
- Keep a fixture of real strings next to the pattern, including nasty ones.
- Prefer a simple pattern plus ordinary code (length checks, a phone library) over one giant expression.
- Remember that
.does not match a newline unless your flavour says so, and thatmultilineis not the same as “dot matches all”. - Never paste production secrets into a test string on a shared computer.
FAQ
Which flags can I set?
Global (g), Ignore case (i) and Multiline (m), each as a checkbox next to the pattern.
Why is only the first match highlighted?
Global (g) is probably off. Turn it on when you want every match in the test string.
Do I need an account?
No. The page describes the tester as free, with no sign-up for the core workflow.
Disclosure: I build ToolSphare, the free tools site that hosts the regex tester described above.