[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5549":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":18,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":22,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":40,"readmeContent":41,"aiSummary":42,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":43,"discoverSource":44},5549,"grex","pemistahl\u002Fgrex","pemistahl","A command-line tool and Rust library with Python bindings for generating regular expressions from user-provided test cases","https:\u002F\u002Fpemistahl.github.io\u002Fgrex-js\u002F",null,"Rust",8135,193,43,8,0,2,6,24,72.26,"Apache License 2.0",false,"main",[25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],"cli","command-line-tool","python","python-library","regex","regex-pattern","regexp","regular-expression","regular-expressions","rust","rust-cli","rust-crate","rust-library","terminal","tool","2026-06-12 04:00:25","\u003Cdiv align=\"center\">\n\n  ![grex](https:\u002F\u002Fraw.githubusercontent.com\u002Fpemistahl\u002Fgrex\u002Fmain\u002Flogo.png)\n\n  \u003Cbr>\n\n  [![rust build status](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Factions\u002Fworkflows\u002Frust-build.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Factions\u002Fworkflows\u002Frust-build.yml)\n  [![python build status](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Factions\u002Fworkflows\u002Fpython-build.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Factions\u002Fworkflows\u002Fpython-build.yml)\n  [![docs.rs](https:\u002F\u002Fdocs.rs\u002Fgrex\u002Fbadge.svg)](https:\u002F\u002Fdocs.rs\u002Fgrex)\n  [![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fpemistahl\u002Fgrex\u002Fbranch\u002Fmain\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fpemistahl\u002Fgrex)\n  [![dependency status](https:\u002F\u002Fdeps.rs\u002Fcrate\u002Fgrex\u002F1.4.6\u002Fstatus.svg)](https:\u002F\u002Fdeps.rs\u002Fcrate\u002Fgrex\u002F1.4.6)\n  [![demo](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-Demo%20Website-orange?logo=HTML5&labelColor=white)](https:\u002F\u002Fpemistahl.github.io\u002Fgrex-js\u002F)\n  \n  [![downloads](https:\u002F\u002Fimg.shields.io\u002Fcrates\u002Fd\u002Fgrex.svg)](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fgrex)\n  [![crates.io](https:\u002F\u002Fimg.shields.io\u002Fcrates\u002Fv\u002Fgrex.svg)](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fgrex)\n  [![lib.rs](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flib.rs-v1.4.6-blue)](https:\u002F\u002Flib.rs\u002Fcrates\u002Fgrex)\n  ![supported Python versions](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-%3E%3D%203.12-blue?logo=Python&logoColor=yellow)\n  [![pypi](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPYPI-v1.0.2-blue?logo=PyPI&logoColor=yellow)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fgrex)\n  [![license](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-Apache%202.0-blue.svg)](https:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0)\n\n  [![Linux 64-bit Download](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLinux%2064bit%20Download-v1.4.6-blue?logo=Linux)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Freleases\u002Fdownload\u002Fv1.4.6\u002Fgrex-v1.4.6-x86_64-unknown-linux-musl.tar.gz)\n  [![Linux ARM64 Download](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLinux%20ARM64%20Download-v1.4.6-blue?logo=Linux)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Freleases\u002Fdownload\u002Fv1.4.6\u002Fgrex-v1.4.6-aarch64-unknown-linux-musl.tar.gz)  \n  \n  [![MacOS 64-bit Download](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FmacOS%2064bit%20Download-v1.4.6-blue?logo=Apple)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Freleases\u002Fdownload\u002Fv1.4.6\u002Fgrex-v1.4.6-x86_64-apple-darwin.tar.gz)\n  [![MacOS ARM64 Download](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FmacOS%20ARM64%20Download-v1.4.6-blue?logo=Apple)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Freleases\u002Fdownload\u002Fv1.4.6\u002Fgrex-v1.4.6-aarch64-apple-darwin.tar.gz)\n  \n  [![Windows 64-bit Download](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FWindows%2064bit%20Download-v1.4.6-blue?logo=Windows)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Freleases\u002Fdownload\u002Fv1.4.6\u002Fgrex-v1.4.6-x86_64-pc-windows-msvc.zip)\n  [![Windows ARM64 Download](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FWindows%20ARM64%20Download-v1.4.6-blue?logo=Windows)](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Freleases\u002Fdownload\u002Fv1.4.6\u002Fgrex-v1.4.6-aarch64-pc-windows-msvc.zip)\n\u003C\u002Fdiv>\n\n\u003Cbr>\n\n![grex demo](https:\u002F\u002Fraw.githubusercontent.com\u002Fpemistahl\u002Fgrex\u002Fmain\u002Fdemo.gif)\n\n\u003Cbr>\n\n## 1. What does this tool do?\n\n*grex* is a library as well as a command-line utility that is meant to simplify the often \ncomplicated and tedious task of creating regular expressions. It does so by automatically \ngenerating a single regular expression from user-provided test cases. The resulting\nexpression is guaranteed to match the test cases which it was generated from.\n\nThis project has started as a Rust port of the JavaScript tool \n[*regexgen*](https:\u002F\u002Fgithub.com\u002Fdevongovett\u002Fregexgen) written by \n[Devon Govett](https:\u002F\u002Fgithub.com\u002Fdevongovett). Although a lot of further useful features \ncould be added to it, its development was apparently ceased several years ago. The plan \nis now to add these new features to *grex* as Rust really shines when it comes to \ncommand-line tools. *grex* offers all features that *regexgen* provides, and more.\n\nThe philosophy of this project is to generate the most specific regular expression \npossible by default which exactly matches the given input only and nothing else. \nWith the use of command-line flags (in the CLI tool) or preprocessing methods \n(in the library), more generalized expressions can be created.\n\nThe produced expressions are [Perl-compatible regular expressions](https:\u002F\u002Fwww.pcre.org) which are also \ncompatible with the regular expression parser in Rust's [*regex* crate](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fregex).\nOther regular expression parsers or respective libraries from other programming languages \nhave not been tested so far, but they ought to be mostly compatible as well.\n\n## 2. Do I still need to learn to write regexes then?\n\n**Definitely, yes!** Using the standard settings, *grex* produces a regular expression that is guaranteed\nto match only the test cases given as input and nothing else. \nThis has been verified by [property tests](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Fblob\u002Fmain\u002Ftests\u002Fproperty_tests.rs).\nHowever, if the conversion to shorthand character classes such as `\\w` is enabled, the resulting regex matches\na much wider scope of test cases. Knowledge about the consequences of this conversion is essential for finding\na correct regular expression for your business domain.\n\n*grex* uses an algorithm that tries to find the shortest possible regex for the given test cases.\nVery often though, the resulting expression is still longer or more complex than it needs to be.\nIn such cases, a more compact or elegant regex can be created only by hand.\nAlso, every regular expression engine has different built-in optimizations. *grex* does not know anything\nabout those and therefore cannot optimize its regexes for a specific engine.\n\n**So, please learn how to write regular expressions!** The currently best use case for *grex* is to find\nan initial correct regex which should be inspected by hand if further optimizations are possible.  \n\n## 3. Current Features\n- literals\n- character classes\n- detection of common prefixes and suffixes\n- detection of repeated substrings and conversion to `{min,max}` quantifier notation\n- alternation using `|` operator\n- optionality using `?` quantifier\n- escaping of non-ascii characters, with optional conversion of astral code points to surrogate pairs\n- case-sensitive or case-insensitive matching\n- capturing or non-capturing groups\n- optional anchors `^` and `$`\n- fully compliant to [Unicode Standard 16.0](https:\u002F\u002Funicode.org\u002Fversions\u002FUnicode15.0.0)\n- fully compatible with [*regex* crate 1.11.0+](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fregex)\n- correctly handles graphemes consisting of multiple Unicode symbols\n- reads input strings from the command-line or from a file\n- produces more readable expressions indented on multiple using optional verbose mode \n- optional syntax highlighting for nicer output in supported terminals\n\n## 4. How to install?\n\n### 4.1 The command-line tool\n\nYou can download the self-contained executable for your platform above and put it in a place of your choice. \nAlternatively, pre-compiled 64-Bit binaries are available within the package managers [Scoop](https:\u002F\u002Fscoop.sh) \n(for Windows), [Homebrew](https:\u002F\u002Fbrew.sh) (for macOS and Linux), [MacPorts](https:\u002F\u002Fwww.macports.org) (for macOS), and [Huber](https:\u002F\u002Fgithub.com\u002Finnobead\u002Fhuber) (for macOS, Linux and Windows). \n[Raúl Piracés](https:\u002F\u002Fgithub.com\u002Fpiraces) has contributed a [Chocolatey Windows package](https:\u002F\u002Fcommunity.chocolatey.org\u002Fpackages\u002Fgrex).\n\n*grex* is also hosted on [crates.io](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fgrex), \nthe official Rust package registry. If you are a Rust developer and already have the Rust \ntoolchain installed, you can install by compiling from source using \n[*cargo*](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002F), the Rust package manager.\nSo the summary of your installation options is:\n\n```\n( brew | cargo | choco | huber | port | scoop ) install grex\n```\n\n### 4.2 The library\n\nIn order to use *grex* as a library, simply add it as a dependency to your `Cargo.toml` file:\n\n```toml\n[dependencies]\ngrex = { version = \"1.4.6\", default-features = false }\n```\n\nThe dependency *clap* is only needed for the command-line tool.\nBy disabling the default features, the download and compilation of clap is prevented for the library.\n\n## 5. How to use?\n\nDetailed explanations of the available settings are provided in the [library section](#52-the-library).\nAll settings can be freely combined with each other.\n\n### 5.1 The command-line tool\n\nTest cases are passed either directly (`grex a b c`) or from a file (`grex -f test_cases.txt`).\n*grex* is able to receive its input from Unix pipelines as well, e.g. `cat test_cases.txt | grex -`.\n\nThe following table shows all available flags and options:\n\n```\n$ grex -h\n\ngrex 1.4.6\n© 2019-today Peter M. Stahl \u003Cpemistahl@gmail.com>\nLicensed under the Apache License, Version 2.0\nDownloadable from https:\u002F\u002Fcrates.io\u002Fcrates\u002Fgrex\nSource code at https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\n\ngrex generates regular expressions from user-provided test cases.\n\nUsage: grex [OPTIONS] {INPUT...|--file \u003CFILE>}\n\nInput:\n  [INPUT]...         One or more test cases separated by blank space\n  -f, --file \u003CFILE>  Reads test cases on separate lines from a file\n\nDigit Options:\n  -d, --digits      Converts any Unicode decimal digit to \\d\n  -D, --non-digits  Converts any character which is not a Unicode decimal digit to \\D\n\nWhitespace Options:\n  -s, --spaces      Converts any Unicode whitespace character to \\s\n  -S, --non-spaces  Converts any character which is not a Unicode whitespace character to \\S\n\nWord Options:\n  -w, --words      Converts any Unicode word character to \\w\n  -W, --non-words  Converts any character which is not a Unicode word character to \\W\n\nEscaping Options:\n  -e, --escape           Replaces all non-ASCII characters with unicode escape sequences\n      --with-surrogates  Converts astral code points to surrogate pairs if --escape is set\n\nRepetition Options:\n  -r, --repetitions\n          Detects repeated non-overlapping substrings and converts them to {min,max} quantifier\n          notation\n      --min-repetitions \u003CQUANTITY>\n          Specifies the minimum quantity of substring repetitions to be converted if --repetitions\n          is set [default: 1]\n      --min-substring-length \u003CLENGTH>\n          Specifies the minimum length a repeated substring must have in order to be converted if\n          --repetitions is set [default: 1]\n\nAnchor Options:\n      --no-start-anchor  Removes the caret anchor `^` from the resulting regular expression\n      --no-end-anchor    Removes the dollar sign anchor `$` from the resulting regular expression\n      --no-anchors       Removes the caret and dollar sign anchors from the resulting regular\n                         expression\n\nDisplay Options:\n  -x, --verbose   Produces a nicer-looking regular expression in verbose mode\n  -c, --colorize  Provides syntax highlighting for the resulting regular expression\n\nMiscellaneous Options:\n  -i, --ignore-case     Performs case-insensitive matching, letters match both upper and lower case\n  -g, --capture-groups  Replaces non-capturing groups with capturing ones\n  -h, --help            Prints help information\n  -v, --version         Prints version information\n\n \n```\n\n### 5.2 The library\n\n#### 5.2.1 Default settings\n\nTest cases are passed either from a collection via [`RegExpBuilder::from()`](https:\u002F\u002Fdocs.rs\u002Fgrex\u002F1.4.6\u002Fgrex\u002Fstruct.RegExpBuilder.html#method.from) \nor from a file via [`RegExpBuilder::from_file()`](https:\u002F\u002Fdocs.rs\u002Fgrex\u002F1.4.6\u002Fgrex\u002Fstruct.RegExpBuilder.html#method.from_file).\nIf read from a file, each test case must be on a separate line. Lines may be ended with either a newline `\\n` or a carriage\nreturn with a line feed `\\r\\n`.\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"a\", \"aa\", \"aaa\"]).build();\nassert_eq!(regexp, \"^a(?:aa?)?$\");\n```\n\n#### 5.2.2 Convert to character classes\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"a\", \"aa\", \"123\"])\n    .with_conversion_of_digits()\n    .with_conversion_of_words()\n    .build();\nassert_eq!(regexp, \"^(\\\\d\\\\d\\\\d|\\\\w(?:\\\\w)?)$\");\n```\n\n#### 5.2.3 Convert repeated substrings\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"aa\", \"bcbc\", \"defdefdef\"])\n    .with_conversion_of_repetitions()\n    .build();\nassert_eq!(regexp, \"^(?:a{2}|(?:bc){2}|(?:def){3})$\");\n```\n\nBy default, *grex* converts each substring this way which is at least a single character long \nand which is subsequently repeated at least once. You can customize these two parameters if you like.\n\nIn the following example, the test case `aa` is not converted to `a{2}` because the repeated substring \n`a` has a length of 1, but the minimum substring length has been set to 2.\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"aa\", \"bcbc\", \"defdefdef\"])\n    .with_conversion_of_repetitions()\n    .with_minimum_substring_length(2)\n    .build();\nassert_eq!(regexp, \"^(?:aa|(?:bc){2}|(?:def){3})$\");\n```\n\nSetting a minimum number of 2 repetitions in the next example, only the test case `defdefdef` will be\nconverted because it is the only one that is repeated twice.\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"aa\", \"bcbc\", \"defdefdef\"])\n    .with_conversion_of_repetitions()\n    .with_minimum_repetitions(2)\n    .build();\nassert_eq!(regexp, \"^(?:bcbc|aa|(?:def){3})$\");\n```\n\n#### 5.2.4 Escape non-ascii characters\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"You smell like 💩.\"])\n    .with_escaping_of_non_ascii_chars(false)\n    .build();\nassert_eq!(regexp, \"^You smell like \\\\u{1f4a9}\\\\.$\");\n```\n\nOld versions of JavaScript do not support unicode escape sequences for the astral code planes \n(range `U+010000` to `U+10FFFF`). In order to support these symbols in JavaScript regular \nexpressions, the conversion to surrogate pairs is necessary. More information on that matter \ncan be found [here](https:\u002F\u002Fmathiasbynens.be\u002Fnotes\u002Fjavascript-unicode).\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"You smell like 💩.\"])\n    .with_escaped_non_ascii_chars(true)\n    .build();\nassert_eq!(regexp, \"^You smell like \\\\u{d83d}\\\\u{dca9}\\\\.$\");\n```\n\n#### 5.2.5 Case-insensitive matching\n\nThe regular expressions that *grex* generates are case-sensitive by default.\nCase-insensitive matching can be enabled like so:\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"big\", \"BIGGER\"])\n    .with_case_insensitive_matching()\n    .build();\nassert_eq!(regexp, \"(?i)^big(?:ger)?$\");\n```\n\n#### 5.2.6 Capturing Groups\n\nNon-capturing groups are used by default. \nExtending the previous example, you can switch to capturing groups instead.\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"big\", \"BIGGER\"])\n    .with_case_insensitive_matching()\n    .with_capturing_groups()\n    .build();\nassert_eq!(regexp, \"(?i)^big(ger)?$\");\n```\n\n#### 5.2.7 Verbose mode\n\nIf you find the generated regular expression hard to read, you can enable verbose mode.\nThe expression is then put on multiple lines and indented to make it more pleasant to the eyes.\n\n```rust\nuse grex::RegExpBuilder;\nuse indoc::indoc;\n\nlet regexp = RegExpBuilder::from(&[\"a\", \"b\", \"bcd\"])\n    .with_verbose_mode()\n    .build();\n\nassert_eq!(regexp, indoc!(\n    r#\"\n    (?x)\n    ^\n      (?:\n        b\n        (?:\n          cd\n        )?\n        |\n        a\n      )\n    $\"#\n));\n```\n\n#### 5.2.8 Disable anchors\n\nBy default, the anchors `^` and `$` are put around every generated regular expression in order\nto ensure that it matches only the test cases given as input. Often enough, however, it is\ndesired to use the generated pattern as part of a larger one. For this purpose, the anchors\ncan be disabled, either separately or both of them.\n\n```rust\nuse grex::RegExpBuilder;\n\nlet regexp = RegExpBuilder::from(&[\"a\", \"aa\", \"aaa\"])\n    .without_anchors()\n    .build();\nassert_eq!(regexp, \"a(?:aa?)?\");\n```\n\n### 5.3 Examples\n\nThe following examples show the various supported regex syntax features:\n\n```shell\n$ grex a b c\n^[a-c]$\n\n$ grex a c d e f\n^[ac-f]$\n\n$ grex a b x de\n^(?:de|[abx])$\n\n$ grex abc bc\n^a?bc$\n\n$ grex a b bc\n^(?:bc?|a)$\n\n$ grex [a-z]\n^\\[a\\-z\\]$\n\n$ grex -r b ba baa baaa\n^b(?:a{1,3})?$\n\n$ grex -r b ba baa baaaa\n^b(?:a{1,2}|a{4})?$\n\n$ grex y̆ a z\n^(?:y̆|[az])$\nNote: \nGrapheme y̆ consists of two Unicode symbols:\nU+0079 (Latin Small Letter Y)\nU+0306 (Combining Breve)\n\n$ grex \"I ♥ cake\" \"I ♥ cookies\"\n^I ♥ c(?:ookies|ake)$\nNote:\nInput containing blank space must be \nsurrounded by quotation marks.\n```\n\nThe string `\"I ♥♥♥ 36 and ٣ and 💩💩.\"` serves as input for the following examples using the command-line notation:\n\n```shell\n$ grex \u003CINPUT>\n^I ♥♥♥ 36 and ٣ and 💩💩\\.$\n\n$ grex -e \u003CINPUT>\n^I \\u{2665}\\u{2665}\\u{2665} 36 and \\u{663} and \\u{1f4a9}\\u{1f4a9}\\.$\n\n$ grex -e --with-surrogates \u003CINPUT>\n^I \\u{2665}\\u{2665}\\u{2665} 36 and \\u{663} and \\u{d83d}\\u{dca9}\\u{d83d}\\u{dca9}\\.$\n\n$ grex -d \u003CINPUT>\n^I ♥♥♥ \\d\\d and \\d and 💩💩\\.$\n\n$ grex -s \u003CINPUT>\n^I\\s♥♥♥\\s36\\sand\\s٣\\sand\\s💩💩\\.$\n\n$ grex -w \u003CINPUT>\n^\\w ♥♥♥ \\w\\w \\w\\w\\w \\w \\w\\w\\w 💩💩\\.$\n\n$ grex -D \u003CINPUT>\n^\\D\\D\\D\\D\\D\\D36\\D\\D\\D\\D\\D٣\\D\\D\\D\\D\\D\\D\\D\\D$\n\n$ grex -S \u003CINPUT>\n^\\S \\S\\S\\S \\S\\S \\S\\S\\S \\S \\S\\S\\S \\S\\S\\S$\n\n$ grex -dsw \u003CINPUT>\n^\\w\\s♥♥♥\\s\\d\\d\\s\\w\\w\\w\\s\\d\\s\\w\\w\\w\\s💩💩\\.$\n\n$ grex -dswW \u003CINPUT>\n^\\w\\s\\W\\W\\W\\s\\d\\d\\s\\w\\w\\w\\s\\d\\s\\w\\w\\w\\s\\W\\W\\W$\n\n$ grex -r \u003CINPUT>\n^I ♥{3} 36 and ٣ and 💩{2}\\.$\n\n$ grex -er \u003CINPUT>\n^I \\u{2665}{3} 36 and \\u{663} and \\u{1f4a9}{2}\\.$\n\n$ grex -er --with-surrogates \u003CINPUT>\n^I \\u{2665}{3} 36 and \\u{663} and (?:\\u{d83d}\\u{dca9}){2}\\.$\n\n$ grex -dgr \u003CINPUT>\n^I ♥{3} \\d(\\d and ){2}💩{2}\\.$\n\n$ grex -rs \u003CINPUT>\n^I\\s♥{3}\\s36\\sand\\s٣\\sand\\s💩{2}\\.$\n\n$ grex -rw \u003CINPUT>\n^\\w ♥{3} \\w(?:\\w \\w{3} ){2}💩{2}\\.$\n\n$ grex -Dr \u003CINPUT>\n^\\D{6}36\\D{5}٣\\D{8}$\n\n$ grex -rS \u003CINPUT>\n^\\S \\S(?:\\S{2} ){2}\\S{3} \\S \\S{3} \\S{3}$\n\n$ grex -rW \u003CINPUT>\n^I\\W{5}36\\Wand\\W٣\\Wand\\W{4}$\n\n$ grex -drsw \u003CINPUT>\n^\\w\\s♥{3}\\s\\d(?:\\d\\s\\w{3}\\s){2}💩{2}\\.$\n\n$ grex -drswW \u003CINPUT>\n^\\w\\s\\W{3}\\s\\d(?:\\d\\s\\w{3}\\s){2}\\W{3}$\n```                                                                                                                            \n\n## 6. How to build?\n\nIn order to build the source code yourself, you need the \n[stable Rust toolchain](https:\u002F\u002Fwww.rust-lang.org\u002Ftools\u002Finstall) installed on your machine \nso that [*cargo*](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002F), the Rust package manager is available.\n**Please note**: Rust >= 1.70.0 is required to build the CLI. For the library part, Rust \u003C 1.70.0 is sufficient.\n\n```shell\ngit clone https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex.git\ncd grex\ncargo build\n```\n\nThe source code is accompanied by an extensive test suite consisting of unit tests, integration \ntests and property tests. For running them, simply say:\n\n```shell\ncargo test\n```\n\nBenchmarks measuring the performance of several settings can be run with:\n\n```shell\ncargo bench\n```\n\n## 7. Python extension module\n\nWith the help of [PyO3](https:\u002F\u002Fgithub.com\u002FPyO3\u002Fpyo3) and\n[Maturin](https:\u002F\u002Fgithub.com\u002FPyO3\u002Fmaturin), the library has been compiled to a\nPython extension module so that it can be used within any Python software as well.\nIt is available in the [Python Package Index](https:\u002F\u002Fpypi.org\u002Fproject\u002Fgrex) and can \nbe installed with:\n\n```shell\npip install grex\n```\n\nTo build the Python extension module yourself, create a virtual environment and install \n[Maturin](https:\u002F\u002Fgithub.com\u002FPyO3\u002Fmaturin).\n\n```shell\npython -m venv \u002Fpath\u002Fto\u002Fvirtual\u002Fenvironment\nsource \u002Fpath\u002Fto\u002Fvirtual\u002Fenvironment\u002Fbin\u002Factivate\npip install maturin\nmaturin build\n```\n\nThe Python library contains a single class named `RegExpBuilder` that can be imported like so:\n\n```python\nfrom grex import RegExpBuilder\n```\n\n## 8. WebAssembly support\n\nThis library can be compiled to [WebAssembly (WASM)](https:\u002F\u002Fwebassembly.org) which allows to use *grex*\nin any JavaScript-based project, be it in the browser or in the back end running on [Node.js](https:\u002F\u002Fnodejs.org).\n\nThe easiest way to compile is to use [`wasm-pack`](https:\u002F\u002Frustwasm.github.io\u002Fwasm-pack). After the installation,\nyou can, for instance, build the library with the web target so that it can be directly used in the browser:\n\n    wasm-pack build --target web\n\nThis creates a directory named `pkg` on the top-level of this repository, containing the compiled wasm files\nand JavaScript and TypeScript bindings. In an HTML file, you can then call *grex* like the following, for instance:\n\n```html\n\u003Cscript type=\"module\">\n    import init, { RegExpBuilder } from \".\u002Fpkg\u002Fgrex.js\";\n\n    init().then(_ => {\n        alert(RegExpBuilder.from([\"hello\", \"world\"]).build());\n    });\n\u003C\u002Fscript>\n```\n\nThere are also some integration tests available both for Node.js and for the browsers Chrome, Firefox and Safari.\nTo run them, simply say:\n\n    wasm-pack test --node --headless --chrome --firefox --safari\n\nIf the tests fail to start in Safari, you need to enable Safari's web driver first by running:\n\n    sudo safaridriver --enable\n\nThe output of `wasm-pack` will be hosted in a [separate repository](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex-js) which\nallows to add further JavaScript-related configuration, tests and documentation. *grex* will then be added to the\n[npm registry](https:\u002F\u002Fwww.npmjs.com) as well, allowing for an easy download and installation within every JavaScript\nor TypeScript project.\n\nThere is a [demo website](https:\u002F\u002Fpemistahl.github.io\u002Fgrex-js\u002F) available where you can give grex a try.\n\n![demo website](https:\u002F\u002Fraw.githubusercontent.com\u002Fpemistahl\u002Fgrex\u002Fmain\u002Fwebsite.jpg)\n\n## 9. How does it work?\n\n1. A [deterministic finite automaton](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDeterministic_finite_automaton) (DFA) \nis created from the input strings.\n\n2. The number of states and transitions between states in the DFA is reduced by applying \n[Hopcroft's DFA minimization algorithm](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDFA_minimization#Hopcroft.27s_algorithm).\n\n3. The minimized DFA is expressed as a system of linear equations which are solved with \n[Brzozowski's algebraic method](http:\u002F\u002Fcs.stackexchange.com\u002Fquestions\u002F2016\u002Fhow-to-convert-finite-automata-to-regular-expressions#2392), \nresulting in the final regular expression.\n\n## 10. What's next for version 1.5.0?\n\nTake a look at the [planned issues](https:\u002F\u002Fgithub.com\u002Fpemistahl\u002Fgrex\u002Fmilestone\u002F5).\n\n## 11. Contributions\n\nIn case you want to contribute something to *grex*, I encourage you to do so.\nDo you have ideas for cool features? Or have you found any bugs so far? \nFeel free to open an issue or send a pull request. It's very much appreciated. :-)\n","grex 是一个用于从用户提供的测试用例生成正则表达式的命令行工具和 Rust 库，并提供了 Python 绑定。其核心功能是通过分析给定的字符串示例，自动生成能够匹配这些示例的正则表达式，从而简化了正则表达式的编写过程。技术上，grex 利用了 Rust 的高性能特性来保证处理速度，同时也支持多种操作系统平台，包括 Linux、macOS 和 Windows。此外，它还为 Python 用户提供了方便的接口，使得不同编程背景的开发者都能轻松使用。该工具非常适合需要频繁处理文本数据、进行模式识别或数据验证的场景，如日志分析、表单验证等任务。","2026-06-11 03:03:53","top_language"]