Can I test if a regex is valid in C# without throwing exception

后端 未结 8 1881
挽巷
挽巷 2020-12-03 13:19

I allow users to enter a regular expression to match IP addresses, for doing an IP filtration in a related system. I would like to validate if the entered regular expression

8条回答
  •  忘掉有多难
    2020-12-03 13:42

    Depending on who the target is for this, I'd be very careful. It's not hard to construct regexes that can backtrack on themselves and eat a lot of CPU and memory -- they can be an effective Denial of Service vector.

提交回复
热议问题