英文:
Convert regex from Java to Go
问题
我使用reregexp2库。
这个正则表达式在Go中不起作用,会报错:
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_])
我希望它能正常执行。
英文:
(?<=^|[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
答案1
得分: 0
如果你查看Java regex Pattern documentation
,你会发现\p{Punct}
表示的是标点符号:其中包括!"#$%&'()*+,-./:;<=>?@[]^_{|}~。
所以,如果你想将其转换为Go语言的正则表达式,请参考regexp syntax documentation
。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论