uhop / node-re2

node.js bindings for RE2: fast, safe alternative to backtracking regular expression engines.
Other
479 stars 53 forks source link

Replace provide different results for node-re2 / re2j / re2js / golang #183

Closed le0pard closed 11 months ago

le0pard commented 12 months ago

Hello. Thanks for your work with this port for node.js.

Found some difference in replacement work and decided to ask here:

regex = (.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) string = abcdefghijklmnopqrstuvwxyz123 replacement = $10$20

we need to do "replace all":

Is this expected behaviour or need in some other way to do "replace all" in node-re2? Thanks

P.S. Native JS implementation:

r = new RegExp('(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)', 'g')
'abcdefghijklmnopqrstuvwxyz123'.replace(r, '$10$20') // => 'jb0wo0123'
le0pard commented 11 months ago

Added possible fix - https://github.com/uhop/node-re2/pull/184