When is it best to use Regular Expressions over basic string splitting / substring'ing?

前端 未结 7 1566
旧巷少年郎
旧巷少年郎 2020-12-01 12:46

It seems that the choice to use string parsing vs. regular expressions comes up on a regular basis for me anytime a situation arises that I need part of a string, informatio

相关标签:
7条回答
  • 2020-12-01 13:18

    I would always use a regex unless it's something very simple such as splitting a comma-separated string. If I think there's a chance the strings might one day get more complicated, I'll probably start with a regex.

    I don't subscribe to the view that regexes are hard or complicated. It's one tool that every developer should learn and learn well. They have a myriad of uses, and once learned, this is exactly the sort of thing you never have to worry about ever again.

    Regexes are rarely overkill - if the match is simple, so is the regex.

    0 讨论(0)
提交回复
热议问题