+ 3

What should i use: RegEx or String.Contains?

I want to build a tool, to filter a lot of incoming messages(I know the stuff i want to filter, so it is not necessary to change it at runtime), but i'm not sure what the best method is: PreCompile a regex structure or filter with string.contains/ stringbuilder? I hope you can give me some advices or hints! Thank you!

30th Oct 2018, 6:25 PM
acki
3 odpowiedzi
+ 1
I personally would go for regular expressions. They are very flexible, so if you ever need your filter to seek other contents, it will still be easy to implement, whereas the string.contains method is extremely capricious about the format of the text you pass it, and you will have a very hard time making it work if you don't stick to the format.
31st Oct 2018, 2:02 AM
PaintingJo
PaintingJo - avatar
+ 1
Depends on what you are looking for. I usually just use regex for characters, number and symbols. I use includes() for strings.
1st Nov 2018, 5:53 PM
Brandon
Brandon - avatar