Home > Mobile >  Convert regex from Java to Go
Convert regex from Java to Go

Time:01-09

(?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([A-Z][A-Z0-9_]*-\d )(?![^\W_])

I use the library reregexp2

This RE does not work in Go and will report error:

regexp2: Compile(`(?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([A-Z][A-Z0-9_]*-\d )(?![^\W_])`): error parsing regexp: unknown unicode category, script, or property 'Punct' in `(?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([A-Z][A-Z0-9_]*-\d )(?![^\W_])`

I hope it can be executed normally

CodePudding user response:

If you take a look at Java regex Pattern documentation, you'll see that \p{Punct} is Punctuation: One of !"#$%&'()* ,-./:;<=>?@[\]^_{|}~

\p{Punct} Punctuation: One of !"#$%&'()* ,-./:;<=>?@[]^_`{|}~

So what you need to convert this to a go regex checking the regexp syntax documentation

  • Related