What is Ruby Regex Tester?
Ruby Regex Tester — A Ruby regex tester lets you prototype and debug regular expressions for Ruby — patterns used with =~, match?, scan, and gsub — with instant match highlighting, then export ready-to-run Ruby code.
Loading your tools...
Test Ruby regular expressions with live match highlighting and capture groups, then copy working Ruby code — =~, match?, scan, or gsub.
Ruby Regex Tester: Paste your pattern and a test string to see matches and capture groups instantly, then copy the generated Ruby snippet (using String#match and scan). Standard patterns — character classes, quantifiers, anchors, groups, named captures — behave identically in Ruby's Onigmo engine and this tester; the compatibility table below covers the differences like /m and POSIX classes.
Loading Tool...
Ruby Regex Tester — A Ruby regex tester lets you prototype and debug regular expressions for Ruby — patterns used with =~, match?, scan, and gsub — with instant match highlighting, then export ready-to-run Ruby code.
Enter your regular expression pattern — the tester highlights matches as you type.
Paste a realistic test string, including inputs that should NOT match.
Open the code generator (preset to Ruby) and copy the ready-to-run snippet.
Check the compatibility table below for the few Ruby-specific differences before shipping.
Matching in the browser runs on JavaScript's RegExp. Here is exactly how Ruby's Onigmo (Oniguruma) engine lines up, feature by feature:
| Feature | Ruby | This tester (JS) |
|---|---|---|
| Named capture groups | (?<name>…) — also creates local vars with =~ | (?<name>…) — identical syntax |
| Dot matches newline | /m flag | /s flag (m means multiline anchors) |
| Multiline anchors (^ $ per line) | always on — ^ and $ match line boundaries by default | needs /m flag |
| String-start/end anchors | \A and \z (\Z allows trailing newline) | only ^ and $ (without m) |
| POSIX character classes | [[:alpha:]], [[:digit:]] supported | not supported — use \p{L}, \d |
| Unicode property classes | \p{Hiragana} etc., built in | \p{…} works with the u flag |
| Case-insensitive | /i | /i — identical |
| Free-spacing comments | /x flag | not supported |
For the everyday 90% of patterns — validations, extractions, splits — what matches here matches in Ruby, because both engines implement the same Perl-derived core. The gotcha that actually bites people is the /m flag: Ruby's /m makes the dot match newlines (JavaScript calls that /s), while Ruby's ^ and $ always match at line boundaries (JavaScript needs /m for that). So if your pattern relies on anchors across multi-line text or dot-matches-newline, double-check the flag mapping in the table above before pasting into your Ruby code. When you need Ruby-exclusive syntax — [[:alpha:]], \A, \h, or the /x free-spacing mode — verify the final pattern in irb: `"text" =~ /pattern/` or `"text".match?(/pattern/)`.
Ruby gives you several ways to apply a regex, and the right one depends on what you want back. `string =~ /re/` returns the match index (and fills $~ plus named-capture locals). `string.match(/re/)` returns a MatchData with capture groups. `string.match?(/re/)` (Ruby 2.4+) is the fastest boolean check — no MatchData allocation. `string.scan(/re/)` returns every match as an array — the equivalent of this tester's g flag. `string.gsub(/re/, replacement)` is find-and-replace, with \1 \2 backreferences or a block. The code generator above produces a runnable snippet using match and scan; swap in match? when you only need true/false.
g=global, i=ignoreCase, m=multiline, s=dotAll, u=unicode, y=sticky