DevToys Pro

free web developer tools

Blog
Rate us:
Try browser extension:
← Back to Blog

Dev Blog: RegEx Tester, JSONPath, and XML Validator

9 min read

Testing regexp patterns, querying JSON structures, and validating XML documents are essential skills for developers working with data parsing, input validation, and API integration. These tools help catch errors before they reach production.

This guide covers the testing and validation tools developers rely on — with practical examples for regex pattern matching, JSONPath queries, and XML syntax checking.


Regular Expression Tester

A regex tester lets you experiment with regular expressions in real-time, showing matches, capture groups, and validation results instantly. This is faster and safer than testing patterns directly in code.

Regex Basics

// Character classes
\d     digit (0-9)
\w     word character (a-z, A-Z, 0-9, _)
\s     whitespace (space, tab, newline)
.      any character except newline

// Quantifiers
*      zero or more
+      one or more
?      zero or one
{n}    exactly n times
{n,m}  between n and m times

// Anchors
^      start of string/line
$      end of string/line
\b     word boundary

Common Regex Patterns

// Email (simplified)
^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$

// URL
^https?://[\w.-]+(/[\w./-]*)?$

// Phone (US)
^\+?1?[-.]?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}$

// IPv4 address
^(?:\d{1,3}\.){3}\d{1,3}$

// Date (YYYY-MM-DD)
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$

// UUID
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$

Regex New Line and Multiline Patterns

Handling regex new line matching is a common challenge. By default, . doesn't match newlines:

// Input text with newlines
Line 1
Line 2
Line 3

// Pattern: .*
// Without flags: matches "Line 1" only (stops at newline)

// With 's' flag (dotall): .* matches everything including newlines
// With 'm' flag (multiline): ^ and $ match line boundaries

// Matching newlines explicitly
\n        Unix newline (LF)
\r\n      Windows newline (CRLF)
\r        Old Mac newline (CR)
[\r\n]+   Any newline sequence

// Match across lines without 's' flag
[\s\S]*   Any character including newlines
[\d\D]*   Alternative: digit or non-digit (everything)

Regex Flags

FlagNameEffect
gGlobalFind all matches, not just first
iCase-insensitiveIgnore upper/lowercase
mMultiline^ and $ match line boundaries
sDotall. matches newlines
uUnicodeEnable Unicode support

Capture Groups and Backreferences

// Capture groups with ()
Pattern: (\d{4})-(\d{2})-(\d{2})
Input:   2025-12-21
Groups:  $1 = 2025, $2 = 12, $3 = 21

// Named capture groups
Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})

// Non-capturing groups
Pattern: (?:https?://)?www\.example\.com
         └── doesn't create a capture group

// Backreferences (match same text again)
Pattern: (\w+)\s+\1
Matches: "the the" (repeated word detection)

Regex Testing Best Practices

  • Test with edge cases: empty strings, special characters, Unicode
  • Check for catastrophic backtracking with nested quantifiers
  • Use non-capturing groups when you don't need the match
  • Anchor patterns (^ and $) to avoid partial matches
  • Document complex patterns with comments (use verbose mode)

The Regular Expression Tester shows matches in real-time with highlighting, capture groups, and flag configuration.


JSONPath Tester & Evaluator

JSONPath is a query language for JSON, similar to XPath for XML. A JSONPath tester helps you build and validate queries before implementing them in code.

JSONPath Syntax

// Sample JSON
{
  "store": {
    "books": [
      { "title": "Clean Code", "price": 35.99, "author": "Martin" },
      { "title": "Refactoring", "price": 49.99, "author": "Fowler" }
    ],
    "location": "NYC"
  }
}

// JSONPath expressions
$                    Root object
$.store              store object
$.store.books        books array
$.store.books[0]     First book
$.store.books[-1]    Last book
$.store.books[*]     All books
$.store.books[0,1]   First two books
$.store.books[0:2]   Slice: index 0 to 1

JSONPath Operators

// Deep scan (recursive descent)
$..title             All titles at any depth
$..price             All prices in document

// Filter expressions
$.store.books[?(@.price < 40)]
                     Books under $40

$.store.books[?(@.author == 'Martin')]
                     Books by Martin

// Wildcard
$.store.*            All direct children of store
$[*]                 All elements if root is array

// Array operations
$.store.books.length Number of books

JSONPath Use Cases

  • API response extraction — Pull specific values from nested JSON
  • Configuration parsing — Extract settings from JSON configs
  • Log analysis — Query JSON-formatted logs
  • Data transformation — Map JSON to different structures
  • Testing assertions — Validate API response structure

JSONPath vs JavaScript

// Equivalent operations

// JSONPath
$.store.books[?(@.price > 40)].title

// JavaScript
data.store.books
  .filter(book => book.price > 40)
  .map(book => book.title)

// JSONPath is more concise for deep queries
$..books[*].author   // All authors anywhere

// JavaScript requires explicit traversal
function findAuthors(obj) {
  // Recursive search needed
}

The JSONPath Tester evaluates expressions against your JSON and displays results with syntax highlighting.


XML Validation & Syntax Checking

An XML validator checks that XML documents are well-formed and follow correct syntax. Invalid XML breaks parsers, so validation is essential before processing.

XML Well-Formedness Rules

<!-- Well-formed XML requirements -->

1. Single root element
 <root><child/></root>
 <item/><item/>  (multiple roots)

2. Properly nested elements
 <a><b></b></a>
 <a><b></a></b>  (improper nesting)

3. Closed tags
 <element></element>
 <element/>  (self-closing)
 <element>   (unclosed)

4. Case-sensitive tags
 <Item></Item>
 <Item></item>  (case mismatch)

5. Quoted attributes
 <item id="1">
 <item id=1>    (unquoted)

6. Escaped special characters
 &lt; &gt; &amp; &quot; &apos;
 < > & in text content

Common XML Errors

<!-- Error: Unescaped ampersand -->
<company>Smith & Jones</company>
Fix: <company>Smith &amp; Jones</company>

<!-- Error: Unescaped less-than -->
<condition>if x < 10</condition>
Fix: <condition>if x &lt; 10</condition>
Or:  <condition><![CDATA[if x < 10]]></condition>

<!-- Error: Invalid character in element name -->
<2ndItem>value</2ndItem>
Fix: <item2>value</item2>  (can't start with number)

<!-- Error: Missing XML declaration encoding -->
<?xml version="1.0"?>  <!-- OK for UTF-8 -->
<?xml version="1.0" encoding="UTF-8"?>  <!-- Explicit -->

CDATA Sections

CDATA sections let you include text that would otherwise need escaping:

<!-- Without CDATA (escaped) -->
<script>
  if (a &lt; b &amp;&amp; c &gt; d) { }
</script>

<!-- With CDATA (unescaped) -->
<script><![CDATA[
  if (a < b && c > d) { }
]]></script>

XML Namespaces

<!-- Default namespace -->
<root xmlns="http://example.com/ns">
  <child>inherits namespace</child>
</root>

<!-- Prefixed namespace -->
<root xmlns:ex="http://example.com/ns">
  <ex:child>uses ex: prefix</ex:child>
</root>

<!-- Multiple namespaces -->
<root xmlns="http://default.com"
      xmlns:other="http://other.com">
  <element>default namespace</element>
  <other:element>other namespace</other:element>
</root>

XML Validation Scenarios

  • API payloads — Validate SOAP requests before sending
  • Config files — Check Maven pom.xml, web.config syntax
  • Data imports — Validate XML exports from external systems
  • RSS/Atom feeds — Ensure feed structure is valid
  • SVG files — Check vector graphic markup
  • XHTML — Validate strict HTML as XML

The XML Validator checks well-formedness and reports errors with line numbers and descriptions.


Testers Quick Reference

TaskToolKey Features
Pattern matchingRegEx TesterReal-time matches, groups, flags
JSON queryingJSONPath TesterExpression evaluation, filtering
XML syntax checkingXML ValidatorWell-formedness, error reporting

Related Tools

Testing tools work alongside other utilities:


All Testers in DevToys Pro

These tools are part of the Testers collection in DevToys Pro. All validation happens in your browser — your data stays private.

Open Testers →