When not to use Regex in C# (or Java, C++, etc.)

后端 未结 7 1246
囚心锁ツ
囚心锁ツ 2020-11-28 13:12

It is clear that there are lots of problems that look like a simple regex expression will solve, but which prove to be very hard to solve with regex.

<
7条回答
  •  囚心锁ツ
    2020-11-28 14:15

    Don't try to use regex to parse hierarchical text like program source (or nested XML): they are proven to be not powerful enough for that, for example, they can't, for a string of parens, figure out whether they're balanced or not.

    Use parser generators (or similar technologies) for that.

    Also, I'd not recommend using regex to validate data with strict formal standards, like e-mail addresses. They're harder than you want, and you'll either have unaccurate or a very long regex.

提交回复
热议问题