-6

I want to find the regex pattern to find the text between a string and a char and replace spaces in the text with _.

Example. < Node Type="Text">Event Log < /Node >

Expected output : Event_Log

Thanks in advance. Please help.

Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42

3 Answers3

2
        string s = "here is my text $$$ Hello World </stop>";
        Match m = Regex.Match(s, "(\\$[^<]*)<");
        if (m.Success)
        {
            Console.WriteLine(m.Groups[1].Value);
        }
Petar Ivanov
  • 91,536
  • 11
  • 82
  • 95
1
string str = "$$$ Hello World </stop>";
string sPattern = "[\\$]{3}([\\d\\s\\w]*)</stop>";

Match m = Regex.Match(str, sPattern, RegexOptions.IgnoreCase);

if (m.Success) {
    Console.WriteLine(m.Groups(1));
}

Converted from VB code and not tested after but should be ok.

japesu
  • 134
  • 1
  • 10
0

Assuming the example is correct and the text of your question wrong, you need:

\$+[^$<]*(?=<)

If it's the other way around, try this:

(?<=\$+)[^$<]*<

BTW, all questions like this can be more easily answered using a tool like this online regex tester.

Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94