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

前端 未结 7 1656
旧巷少年郎
旧巷少年郎 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 12:57

    When your required transformation isn't basic -- but is still conceptually simple.

    no reason to pull out Regex if you're doing a straight string replacement, for example... its easier to just use the string.Replace

    on the other hand, a complex rule with many conditionals or special cases that would take more than 50 characters of regex can be a nightmare to maintain later on if you don't explicitly write it out

提交回复
热议问题