Reputation: 151
I want to exclude the following characters from my string:
\--
'
<
>
Please tell me how to write a regular expression for this.
Upvotes: 0
Views: 3382
Reputation: 21999
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, @"['<>]|\\--", "");
Upvotes: 0
Reputation: 25687
string s = Regex.Replace(SomeString, "[\-'<>]", "");
Hope this helps.
Upvotes: 0
Reputation: 32266
Personally I'd just use string.Replace. Regular expressions are great, but should be used wisely.
Upvotes: 2
Reputation: 38603
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.
Upvotes: 0