A compiled-away, type-safe, readable RegExp alternative ↦
This isn’t the first attempt at making regular expressions more approachable, but it’s the first one I’ve seen that also brings type safety to the table. Example code:
import { createRegExp, exactly, oneOrMore, digit } from 'magic-regexp'
// Quick-and-dirty semver
createRegExp(
oneOrMore(digit)
.as('major')
.and('.')
.and(oneOrMore(digit).as('minor'))
.and(exactly('.').and(oneOrMore(char).as('patch')).optionally())
)
// /(?<major>(\d)+)\.(?<minor>(\d)+)(\.(?<patch>(.)+))?/
Discussion
Sign in or Join to comment or subscribe
Max Coplan
2022-07-29T22:06:59Z ago
This kinda looks like it’s based on the Swift 5.7 RegexBuilder DSL https://developer.apple.com/documentation/RegexBuilder