I want to rewrite some ruby code into c/c++ code, so I want to use a regular expression library implemented in c. it seems that PCRE is a good choice. there are many ruby style regular expressions. how can i convert it into PCRE style automatically.
Ruby regular expressions are PCRE
regular expressions as PCRE stands for Perl Compatible Regular Expressions and defines a particular syntax for the regular expressions it supports.
For help on individual PCRE regex features see the second article I linked to and for ruby specific methods see the first (as you will see, the syntax of the actual regex's used are the same)
EDIT: as pointed out in the comments the regex engine used by ruby is Onigmo
which according to the linked to page has some of the new features of Perl 5.10. PCRE is a regex library and "The current implementation of PCRE corresponds approximately with Perl 5.12" so there may be some discrepancies around the edges. The syntax is largely the same though, look through the Onigmo github page and ruby api dock to see the difference. By and large though it is probably safe to assume that most regexes that you translate from ruby to PCRE will work without problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With