Calculator Input
This page keeps a single stacked layout overall, while the calculator fields switch to three columns on large screens, two on medium, and one on mobile.
Example Data Table
| Pattern body | Subject snippet | Mode | Expected focus | Illustrative result |
|---|---|---|---|---|
[A-Za-z_]+ |
total_sum = taxValue + fee2; |
First | First identifier | total_sum → 9 chars |
\d+ |
v2 build 304 patched 17 times |
Total | All numeric fragments | 2 + 3 + 2 = 7 chars |
(ERROR|WARN|INFO) |
INFO WARN ERROR |
Longest | Longest log level token | ERROR → 5 chars |
user:(\w+) |
user:alice user:bob |
Specific #2 | Second captured username | bob → 3 chars |
\b\w{3}\b |
map api key set |
Average | Average token width | 3 chars average |
Formula Used
mb_strlen(matched_text, encoding)Byte length =
strlen(matched_text)End byte offset =
start_byte + byte_lengthTotal length =
Σ match_lengthAverage length =
Σ match_length / number_of_matches
When you choose a capture group index greater than zero, the calculator measures that specific captured fragment instead of the complete regex match. This is useful for validating token width, username size, identifier constraints, parsed fields, or partial captures inside larger patterns.
The engine also reports start and end offsets so you can trace where a match begins and ends inside the inspected text. That makes debugging easier when lookaheads, alternation, repetition, or optional groups produce unexpected spans.
How to Use This Calculator
- Type the regex pattern body without surrounding delimiters.
- Select a delimiter and add any modifiers you need.
- Choose the capture group index you want to measure.
- Select whether you want the first, specific, longest, shortest, total, or average length.
- Paste the subject text you want to inspect.
- Submit the form to view the result above the calculator.
- Review detailed match rows, offsets, and summary metrics.
- Use the CSV or PDF buttons to export the current results.
Frequently Asked Questions
1. What does this calculator measure exactly?
It measures the length of regex matches or selected capture groups. You can inspect characters, bytes, offsets, totals, averages, and occurrence-specific results from the same submitted expression.
2. Why are character length and byte length different?
Character length counts visible text characters, while byte length counts storage bytes. Multibyte encodings such as UTF-8 often make accented letters, symbols, or emoji consume more bytes than characters.
3. What happens when I choose capture group 0?
Group 0 always represents the full regex match. Any higher number measures a specific captured subpattern instead, which is helpful when only part of the overall match matters.
4. Can I measure the second or third occurrence only?
Yes. Choose the specific occurrence mode, then enter the occurrence number. The calculator returns that selected match length if it exists in the processed result set.
5. Does the calculator validate invalid expressions?
Yes. If the expression fails compilation or execution, the page displays an error message from the regex engine so you can fix delimiters, modifiers, grouping, or text encoding issues.
6. Are offsets shown in characters or bytes?
Both are shown where possible. Byte offsets come directly from the regex engine, while character offsets are estimated using the selected encoding for easier human inspection.
7. When should I export CSV or PDF?
Export when you need to share debugging evidence, retain pattern test output, compare runs, document parser behavior, or attach structured match data to development notes.
8. Can this help with validation rules and parser testing?
Yes. It is useful for testing token lengths, usernames, IDs, codes, log markers, captured groups, and substring spans before you embed the pattern in production workflows.