regex - Regular expression in C# to replace these string checks -


i wish convert following code regex test path string.

path.contains(".git") || path.contains("_resharper") || path.contains("\\bin\\")  || path.contains("\\obj\\") || path.contains("\\bin\\") || path.contains("\\ipch\\")  || path.contains("\\.git") || path.endswith("\\bin") || path.endswith("\\obj")  || path.endswith("\\bin") || path.endswith("\\ipch");  

any appreciated. cheers

(\.git|_resharper|\\[bb]in\\|\\obj\\|\\ipch\\|\\\.git|\\[bb]in$|\\obj$|\\ipch$)

a full explanation of operators in regex can found @ http://www.regular-expressions.info/reference.html

but basically:

-metacharacters . , \ need escaped backslash interpret them literally

-| means 'match left or match right'. it's or regexes.

-$ means 'the end of string must occur right here' (or in multiline regex mode, end of line or string)

if paste c# string, make sure either @"" string (to escape backslashes having special meaning) or double backslashes (akin doing right now).

edit: shorter version, after noticing contains .git , contains \.git redundant

(\.git|_resharper|\\[bb]in(\\|$)|\\obj(\\|$)|\\ipch(\\|$))


Comments