Is there any way to completely ignore line break and tab characters etc. in RegEx? For instance, the line break and tab characters could be found anywhere and in any order in the content string.
... [CustomToken \t \r\n Type="User" \t \r\n Property="FirstName" \n /] ... [CT ...
The is the RegularExpression that I am currently using:
(\[CustomToken).*?(\/\])
.NET API
Regex.Matches(string input, string pattern)
Thanks for your suggestion.
If you just want that regex to match that input, all you need to do is specify Singleline mode:
Regex.Matches(input, @"\[CustomToken).*?(/\])", RegexOptions.Singleline);
The dot metacharacter normally matches any character except linefeed (\n
). Singleline mode, also known as "dot-matches-all" or "DOTALL" mode, allows it to match linefeeds as well.
There is no way to "ignore" any type of character with regex. You can ignore letter case, but that's about it.
Your best bet is to use \s+
where you would expect some type of whitespace. The \s
class will match any whitespace, including newlines, carriage returns, tabs, and spaces, and this will make your regex pattern look a lot nicer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With