syntax regex package

123 views
Skip to first unread message

Pietro

unread,
Jun 18, 2021, 5:34:20 PM6/18/21
to golang-nuts
Hi all,

I am trying to solve the problem of automatically translating a raft of regexes which were originally intended for GNU sed but that I'd like to run using GoLang, if feasible.

I could not find any syntax options/settings for the regex package which I am assuming is quite strict in its syntax, PCRE or GNULib have options that can change some parts of the syntax.

I am wondering if I am the first one that met this problem or if ready to go solutions are available.

Thanks,
P.

Kurtis Rader

unread,
Jun 18, 2021, 6:02:31 PM6/18/21
to Pietro, golang-nuts
On Fri, Jun 18, 2021 at 2:34 PM Pietro <pietro....@cognitivecredit.com> wrote:
I am trying to solve the problem of automatically translating a raft of regexes which were originally intended for GNU sed but that I'd like to run using GoLang, if feasible.

I could not find any syntax options/settings for the regex package which I am assuming is quite strict in its syntax, PCRE or GNULib have options that can change some parts of the syntax.

See https://golang.org/pkg/regexp/#CompilePOSIX and https://github.com/google/re2/wiki/Syntax. If your sed expressions are in BRE form it's straightforward to translate them to ERE form. It would not surprise me if someone has already written a tool to translate BRE/ERE syntax to Go's RE2 syntax but I'm not aware of any such tool.

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Pietro Paolini

unread,
Jun 20, 2021, 5:51:42 PM6/20/21
to Kurtis Rader, golang-nuts
Thanks for answering - if I am getting this right this is actually pretty straightforward and it seems to be only a business concerning the escaping/unescaping of some characters '|(){}?+' if I am getting this right, so far it's working.


Reply all
Reply to author
Forward
0 new messages