Regular Expressions 101

Community Patterns

1

JSON Parser

Created·2026-07-25 18:00
Flavor·.NET 7.0 (C#)
Description This regular expression is designed to tokenize JSON-like content embedded in INI files. It is not a full JSON validator; instead, it provides a lightweight lexical scanner that identifies structural tokens (objects, arrays, strings, numbers, booleans, null) and ignores comments and whitespace. The token stream is then processed by a hand‑written recursive‑descent parser (with depth‑limit protection) to build a .NET object graph (Dictionary, object], or primitives). Regex Pattern (?//.|/\.?\/)| (?""(?:\\.)"")(?=(?:\s|//.|/\.?\/):)| (?(?true)|(?false)|(?null)|""(?(?:\\.))""|(?-?(?:0|[1-9)(?:\.0-9]+)?(?:[eE?[0-9]+)?))| (?:)| (?\[)| (?,)| (?\])| (?{)| (?})| (?+)| (?[\r\n]+)| (?.+) Named Capture Groups | Group Name | Matches | |------------------|-------------------------------------------------------------------------| | Comment | Single‑line //… or multi‑line /…/ comments (skipped). | | key | A JSON property key (double‑quoted string) followed by a colon (lookahead). | | value | A JSON value – one of: true, false, null, a double‑quoted string, or a number (integer, float, or scientific). | | bool | Sub‑group inside value for true/false (for direct parsing). | | null | Sub‑group for null. | | string | Sub‑group for the content inside double‑quotes (without the quotes). | | number | Sub‑group for numeric literals. | | value_sep | A colon : separating key and value. | | array_open | Left bracket [. | | array_sep | Comma , between array elements. | | array_close | Right bracket ]. | | object_open | Left brace {. | | object_close | Right brace }. | | whitespace | Horizontal whitespace (spaces, tabs) – not newlines. | | newline | Line‑break characters (CR, LF, CRLF). | | undefined | Any other character (should not occur in valid JSON; used as fallback). | Important Notes No recursion – the regex only tokenises; the parser handles nesting and depth limits. Escaped characters inside strings (\n, \t, \", etc.) are not unescaped by the regex – the parser calls UnEscape() when _allowEscapeChars is true. Whitespace and newlines are ignored by the parser (skipped during token iteration). The undefined group uses .+ (not .*) to avoid matching empty positions – this prevents false positives when the scanner reaches the end of the string. Purpose This regex is a solid foundation for building a custom JSON lexer, parser, or tokeniser for .NET projects. Its clear separation of structural elements, comments, and whitespace makes it easy to implement lightweight, hand‑crafted parsers that do not rely on heavy external libraries. It is particularly well‑suited for small to medium‑sized files, configuration blocks, or embedded data fragments, where performance and memory footprint matter. You can adapt the token stream to your own data model, add validation, or transform the JSON on the fly – all while keeping full control over the parsing logic.
Submitted by Pavel Bashkardin
1

email-validation_email_dogrulama

Created·2024-09-09 23:42
Flavor·PCRE2 (PHP)
^ - This indicates the beginning of the expression. - This part specifies that the first character cannot be a digit, hyphen, or underscore. So the first character must be a letter, period, or other special character. [A-z0-9.-]+ - This part requires the username to contain at least one character, and that character can be a letter, digit, period, or hyphen. @ - This represents the "@" symbol in the email address. [A-z.-]+ - This section states that the domain part must contain at least one character, and that character can be a letter, period, or hyphen. . - This represents the period character used to separate the domain from the top-level domain. [A-z]+ - This part requires the top-level domain to contain at least one character, and that character can only be a letter. $ - This indicates the end of the expression. ^ - Bu, ifadenin başlangıcını belirtir. - Bu bölüm, ilk karakterin rakam, tire veya alt çizgi olmaması gerektiğini belirtir. Yani ilk karakter harf, nokta veya diğer özel karakterlerden biri olmalıdır. [A-z0-9.-]+ - Bu kısım, kullanıcı adının en az bir karakter içermesi ve harf, rakam, nokta veya tire karakterlerinden oluşması gerektiğini gösterir. @ - Bu, e-posta adresindeki "@" sembolünü temsil eder. [A-z.-]+ - Bu bölüm, etki alanı kısmının en az bir karakter içermesi ve harf, nokta veya tire karakterlerinden oluşması gerektiğini belirtir. . - Bu, etki alanı uzantısını ayırmak için nokta karakterini gösterir. [A-z]+ - Bu kısım, etki alanı uzantısının en az bir karakter içermesi ve yalnızca harflerden oluşması gerektiğini ifade eder. $ - Bu, ifadenin sonunu belirtir.
Submitted by Emre Yıldırım

Community Library Entry

0

Regular Expression
Created·2022-06-02 06:02
Updated·2022-06-03 00:48
Flavor·JavaScript

Description

This Test will check is the given string is Exactly of 6 digits & all chars are Numbers. use case OTP Validations.

Submitted by anonymous