Edit: MANDATORY CONDITION: Regex has to be inserted into the following statement:
Regex regex = new Regex("<REGEX_STRING>");
val= regex.Matches(val).Cast<Match>().Aggregate("", (s, e) => s + e.Value, s => s);
I found out that I can't use Regex.Replace() method as it was suggested in the answer below.
I am looking for a RegEx that would have to follow two conditions:
accept only a-z, A-Z, 0-9, \s (one or more), and ignore
_(that's why\wis not an option)[!] exclude any
{sq}"substring" anywhere inside the string
*{sq} - it's literally this 4-chars string, not any shortcut for ASCII sign !
What I have so far is:
\b(?!sq)[a-zA-Z0-9 ]*
but this RegEx cuts everything when _ shows up + it also excludes i.e whole [sq].
So for example for a given string:
test[sq]uirrel{sq}_things I should get testsquirrelthings and what I get is: testuirrel
Small input | expected output table below:
| Input string | Expected output |
|---|---|
Na#me |
Name |
M2a_ny |
M2any |
Vari{sq}o@us |
Various |
test [sq]uirrel h23ere! |
test squirrel h23ere |
I would really appreciate any help, it's the most complicated RegEx I have ever came across
