C # - Regex Combine All Words

I need to match all words containing a given string.

string s = "ABC.MYTESTING
XYZ.YOUTESTED
ANY.TESTING";

Regex r = new Regex("(?<TM>[!\..]*TEST.*)", ...);
MatchCollection mc = r.Matches(s);

I need the result:

MYTESTING
YOUTESTED
TESTING

But I get:

TESTING
TESTED
.TESTING

How to achieve this with regular expressions.

Edit: Extended example string.

+5
source share
6 answers

If you searched for all words, including "TEST", you should use

@"(?<TM>\w*TEST\w*)"

\ w contains dictionary characters and abbreviated for [A-Za-z0-9 _]

+3
source

Keep it simple: why not just try \w*TEST\w*as a matching template.

+2
source

:

string s = @"ABC.MYTESTING
XYZ.YOUTESTED
ANY.TESTING";

var m = Regex.Matches(s, @"(\w*TEST\w*)", RegexOptions.IgnoreCase);
+2

\b. . , :

/\b[a-z]+\b/i

BTW,.net /, i - .

.NET Alternative:

var re = new Regex(@"\b[a-z]+\b", RegexOptions.IgnoreCase);
+1

, .

        string s = @"ABC.TESTING
        XYZ.TESTED";
        Regex r = new Regex(@"(?<TM>[!\..]*(?<test>TEST.*))", RegexOptions.Multiline);
        var mc= r.Matches(s);
        foreach (Match match in mc)
        {
            Console.WriteLine(match.Groups["test"]);
        }

, .

, (@"")

0
Regex r = new Regex(@"(?<TM>[^.]*TEST.*)", RegexOptions.IgnoreCase);

-, @manojlds, , . , (, [!\\..]*).

-, -, , [^.]*. ^ - , , !, . , . , , \w* [A-Z]*, , . [!\..] ! ..

Regex r = new Regex(@"(?<TM>[A-Z]*TEST[A-Z]*)", RegexOptions.IgnoreCase);

, , :

Regex r = new Regex(@"(?<TM>\b[A-Z]*TEST[A-Z]*\b)", RegexOptions.IgnoreCase);

, , :

Regex r = new Regex(@"\b[A-Z]*TEST[A-Z]*\b", RegexOptions.IgnoreCase);

Match Value.

0

All Articles