transpiler icon indicating copy to clipboard operation
transpiler copied to clipboard

REGEX

Open mbtools opened this issue 3 years ago • 5 comments
trafficstars

ABAP regex is different from PCRE. However, it looks to me that the transpiler uses PCRE regex.

ABAP Example (from Phone Number exercise, which works without errors in ABAP but fails in Exercism):

    FIND REGEX '1*.*([2-9]\d\d).*([2-9]\d\d).*(\d\d\d\d).*(\d*)' IN `22234567890`
      SUBMATCHES DATA(p1) DATA(p2) DATA(p3) DATA(p4).

image

This works differently in JS

https://regex101.com/r/qhagS7/1

I can make the regex work in JS by using by making the * quantifiers lazy (replace by *?).

https://regex101.com/r/ZbSBTv/1

Not sure what's the best way to fix it. Here're the relevant docs:

https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenregex_migrating_posix.htm

mbtools avatar Mar 28 '22 16:03 mbtools

can the example be reduced?

larshp avatar Mar 29 '22 12:03 larshp

FIND REGEX '(\d\d).*(\d*)' IN `123` SUBMATCHES DATA(p1) DATA(p2).

p1 = '12'. p2 = '3'.

https://regex101.com/r/SMEF5o/1 '12', null https://regex101.com/r/JAjp0V/1 '12', '3'

mbtools avatar Mar 29 '22 15:03 mbtools

yea, try adding the lazy star thing, add some unit tests, we'll see if it works out 😄 but probably better than before

larshp avatar Mar 29 '22 15:03 larshp

but note that https://github.com/abaplint/transpiler/pull/674 probably changes the same file that needs changes

larshp avatar Mar 29 '22 15:03 larshp

new file for handling ABAP regex specifics, transpiler/packages/runtime/src/abap_regex.ts

larshp avatar Apr 29 '22 11:04 larshp