How to match a regex with backreference in Go? -
i need match regex uses backreferences (e.g. \1) in go code.
that's not easy because in go, official regexp package uses re2 engine, 1 have chosen not support backreferences (and other lesser-known features) there can guarantee of linear-time execution, therefore avoiding regex denial-of-service attacks. enabling backreferences support not option re2.
in code, there no risk of malicious exploitation attackers, , need backreferences.
what should do?
regular expressions great working regular grammars, if grammar isn't regular (i.e. requires back-references , stuff that) should switch better tool. there lot of tools available parsing context-free grammars, including yacc shipped go distribution default. alternatively, can write own parser. recursive descent parsers can written hand example.
i think regular expressions overused in scripting languages (like perl, python, ruby, ...) because c/asm powered implementation more optimized languages itself, go isn't such language. regular expressions quite slow , not suited problem @ all.
Comments
Post a Comment