How do you unit test regular expressions?

后端 未结 10 721
长发绾君心
长发绾君心 2020-12-12 11:05

I\'m new to TDD, and I find RegExp quite a particular case. Is there any special way to unit test them, or may I just treat them as regular functions?

10条回答
  •  独厮守ぢ
    2020-12-12 11:31

    I can't believe no one has posted this amazing tool:

    refiddle.com

    It lets you test your regular expressions. You define some text containing strings it should match, and strings it shouldn't match, and if it's all green, you're good. For example here's one I made to match slugs: http://refiddle.com/by/callum-locke/slug-matcher

提交回复
热议问题