b2KIT

Security Regex Pattern Library

Browse and test common security-focused regex patterns for input validation, XSS prevention, and SQL injection detection.

Tested tool guide Tested browser tools Checked August 16, 2026

What Security Regex Pattern Library does, with a checked example

Security regexes are blunt instruments: a single pattern of alternations and character classes that flags text resembling SQL injection, script payloads, or malformed input. This tool organizes a library of such patterns by category and lets you paste any string into a test box to see every match with its position. The surprise most users hit: a match is not a verdict. The pattern fired on literal text, nothing more. Benign strings trip these patterns constantly, and crafted payloads slip past them. They help you recognize and audit suspicious input, not sanitize or protect it.

Worked example

A concrete input and expected output from the current implementation.

Input

Pattern: ('|--|;/\*|\*/)  Test string: Robert'); DROP TABLE Students;--

Expected output

4 matches. First at index 6: the single quote. Also matched: ';' at index 8, ';' at index 29, and '--' at indices 30-31.

The pattern alternates among SQL metacharacters - apostrophe, double hyphen, semicolon, and comment markers - and the scanner reports every occurrence in order, so the first hit is the apostrophe after 'Robert'. Note what the tool does not do: it does not judge whether the string is a working attack, only that it contains the flagged characters.

How the result is produced

1

Library browsing

Patterns are grouped by threat class - input validation, XSS payloads, SQL injection - and each entry shows the regex source, a plain-language description of what it is meant to catch, and a test box. Choosing a pattern loads it as the active pattern in the tester, and the listed example strings give you ready-made inputs to try against it.

2

How the test box works

The tester scans your pasted string for every occurrence of the active pattern and reports the number of matches and their character positions. This is pure text matching: nothing is executed, decoded, or evaluated, and the run happens locally in your browser. Standard regex semantics apply, so alternation order, character classes, anchors, and flags all change what counts as a match.

Good uses

  • Confirming whether a suspicious string in a log, request, or error message actually contains injection metacharacters before you treat it as an attack.
  • Checking your own validation regexes against real-world input: paste addresses, URLs, or usernames and see what your pattern accepts and rejects.
  • Sanity-checking a WAF or input-filter rule against known attack payloads to see which ones it catches and, more importantly, which ones it misses.

Limits and checks

  • A match is not proof of an attack, and no match is not proof of safety. Benign text with apostrophes or double hyphens fires these patterns, while encoded, case-shifted, or whitespace-tricked payloads (such as %27, UNION/**/SELECT, or mixed case) routinely evade them.
  • The patterns detect text; they do not protect anything. SQL injection is prevented with parameterized queries, XSS with context-aware output encoding. Deploying a matching regex as your only defense is a classic false sense of security.
  • Results depend on flags and engine details. An unanchored pattern matches anywhere in the string; case-insensitivity decides whether 'union select' triggers a keyword pattern; and porting a pattern to another language can change escaping and behavior, so re-test after copying it.

Common questions

If my input does not match any pattern, is it safe to use?

No. It only means this particular set of patterns did not fire on this exact string. Attack payloads are open-ended: encodings, case tricks, comments, and newlines produce variants these patterns miss. Treat the tester as a screening tool, and put the real defense in parameterized queries and output encoding rather than in regexes.

Can I copy these patterns straight into my application or WAF?

Mostly yes, with two caveats. Escaping changes between languages, so a pattern written for this tester needs different string escapes in Python, PHP, or a WAF rule language, and flag settings rarely survive copy-paste. Test the deployed pattern against both attack payloads and legitimate input first: over-matching will block real users.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools