5 releases (breaking)

0.11.0 Nov 9, 2023
0.10.0 Mar 21, 2023
0.9.0 Jan 14, 2023
0.8.0 Dec 12, 2022
0.7.0 Sep 10, 2022

#10 in #regex-parser

Download history 88/week @ 2024-02-26 41/week @ 2024-03-04 46/week @ 2024-03-11 93/week @ 2024-03-18 25/week @ 2024-03-25 120/week @ 2024-04-01 50/week @ 2024-04-08 37/week @ 2024-04-15 55/week @ 2024-04-22 31/week @ 2024-04-29 41/week @ 2024-05-06 34/week @ 2024-05-13 49/week @ 2024-05-20 73/week @ 2024-05-27 37/week @ 2024-06-03 31/week @ 2024-06-10

194 downloads per month
Used in 7 crates (via pomsky)

MIT/Apache

140KB
3K SLoC

Pomsky logo

Pomsky

A portable1, modern regular expression language

Website Docs Playground VS Code plugin Discord Crates.io

Get Started

To begin, check out the website.

What's New

Read the blog or the changelog to learn about new features.

Installation

Pre-built binaries can be found on the releases page.

Pomsky can also be installed from source via cargo with cargo install pomsky-bin.

Compatibility

Pomsky is currently compatible with PCRE, JavaScript, Java, .NET, Python, Ruby and Rust. The regex flavor must be specified during compilation, so Pomsky can ensure that the produced regex works as desired on the targeted regex engine.

Note: You should enable Unicode support in your regex engine, if it isn't enabled by default. This is explained here.

Portability

Pomsky aims to be as portable as possible, polyfilling Unicode and unsupported features where feasible. That said, there are some cases where portability is not possible:

  • Some features (e.g. lookaround, backreferences, Unicode properties) aren't supported in every flavor. Pomsky fails to compile when you're using an unsupported feature.

  • \b (word boundaries) are not Unicode aware in JavaScript. Pomsky therefore only allows word boundaries when Unicode is disabled.

  • \w in .NET handles Unicode incorrectly, with no way to polyfill it properly. This means that in .NET, [word] only matches the L, Mn, Nd, and Pc general categories, instead of Alphabetic, M, Nd, Pc and Join_Control.

  • In .NET, ., Codepoint and character classes (e.g. [Latin]) only match a single UTF-16 code unit rather than a codepoint.

  • [space] matches slightly different code points in JavaScript than in Java. This will be fixed.

  • Backreferences behave differently in JavaScript and Python when the referenced group has no captured text. There is nothing we can do about it, but we could add a warning for this in the future.

Security

Never compile or execute an untrusted Pomsky expression on your critical infrastructure. This may make you vulnerable for denial of service attacks, like the Billion Laughs attack.

Read more

Diagnostics

Pomsky looks for mistakes and displays helpful diagnostics:

  • It shows an error if you use a feature not supported by the targeted regex flavor
  • It detects syntax errors and shows suggestions on how to resolve them
  • It parses backslash escapes (which are not allowed in a Pomsky expression) and explains what to write instead
  • It looks for likely mistakes and displays warnings
  • It looks for patterns that can be very slow for certain inputs and are susceptible to Denial-of-Service attacks (coming soon)

Comparison with other projects

I wrote an in-depth comparison with similar projects, which you can find here.

Code of Conduct

The Code of Conduct can be found here.

Contributing

You can contribute by using Pomsky and providing feedback. If you find a bug or have a question, please create an issue.

I also gladly accept code contributions. More information

Sponsor this project

Go to my sponsors page

License

Dual-licensed under the MIT license or the Apache 2.0 license.

Dependencies

~140KB