Skip to content
OddsockLocal
Local
Source text

Formatting

4 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste the text to test.
  2. Set Pattern and Flags. gu is the start.
  3. Leave Action on match to see the JSON, or choose replace and fill in Replacement.
  4. Read match, index, groups and named. An invalid flag or an invalid pattern is an error.

What is Regex tester?

The tester compiles your pattern and shows every match as JSON: the text, the index in the original string, the numbered groups, and any named groups. Pattern \w+ with flags gu against Odd socks in the dryer. finds Odd at 0, socks at 4, in at 10, the at 13 and dryer at 17. The period is not a match, because \w does not include it. That index list is how you see the spaces the pattern skipped.

Read more

Action has two modes. Match is the report. Replace applies the replacement and returns the whole string, not the JSON. Pattern ([bc])at with replacement $1ird on cat bat hat returns cird bird hat. The c and the b were captured. hat does not match, so it stays. Named groups show up on match as the named object; a test of a(?<last>.) against ab ac puts c in the second match’s name last.

Flags are whatever you type. An illegal flag set fails. The library page is a different tool: it offers ready-made patterns for emails, URLs, hashtags, mentions, numbers and phones, and it does not take a free-form pattern. The extractor prints one group as lines. This page is the one that shows where each hit sat.

Use cases

  • You want the indexes of Odd, socks, in, the and dryer so a highlight can be checked against the string.
  • A replacement of ([bc])at with $1ird should turn cat and bat into cird and bird and leave hat alone.
  • A named group last has to show up in the JSON, not only as group number 1.
  • A pattern from the library needs a one-off edit, so you paste it here and change the flags.

Words in a sentence, with indexes

Text Odd socks in the dryer. Pattern \w+. Flags gu. Action match.

Odd at index 0, socks at 4, in at 10, the at 13, dryer at 17. Groups are empty.

Why use Oddsock

The index is the part a yes/no matcher throws away. socks starts at 4, after Odd and a space, and the period never matches \w.

Related tools

Using this tool

\w is letters, digits and underscore. The period in dryer. is punctuation, so the match stops at dryer, index 17.