Skip to content

GNU expr syntax #1126

Answered by BurntSushi
tertsdiepraam asked this question in Q&A
Nov 9, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Unfortunately, it's way worse than what you're picturing here. In theory, if it were just a matter of syntax, then you could write your own parser and lower it to regex-syntax's Hir type (skipping its Ast). From there, you could build a regex from the Hir and you'd be good to go.

But "GNU expr" is, AIUI, built on top of POSIX regexes and POSIX regexes have different match semantics for the same regexes. For example:

$ echo 'samwise' | rg -o 'sam|samwise'
sam
$ echo 'samwise' | grep -E -o 'sam|samwise'
samwise

This is because POSIX uses leftmost-longest semantics where as this crate uses leftmost-first. You can see a description of these modes here: https://docs.rs/aho-corasick/latest/aho…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tertsdiepraam
Comment options

Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants