I want to exclude the following characters from my string:
\--
'
<
>
Please tell me how to write a regular expression for this.
I want to exclude the following characters from my string:
\--
'
<
>
Please tell me how to write a regular expression for this.
If your regex dialect supports lookaheads:
^(?:(?!\\--|['<>]).)*$
However, in some languages it might be cleaner to have a simple manual check rather than use a regex.
string s = Regex.Replace(SomeString, "[\-'<>]", "");
Hope this helps.
Personally I'd just use string.Replace. Regular expressions are great, but should be used wisely.
If the question is how to remove \--
and '
and <
and >
from a string then this regex does the job:
['<>]|\\--
or in C#
resultString = Regex.Replace(subjectString, @"['<>]|\\--", "");