什么是 .net 正则表达式来查找“$”和“<”之间的文本

本文关键字:之间 文本 正则表达式 查找 什么 net | 更新日期: 2023-09-27 18:35:55

我想找到正则表达式模式来查找字符串和字符之间的文本,并将文本中的空格替换为_。

例。 < Node Type="Text">Event Log < /Node >

预期输出 : Event_Log

提前谢谢。请帮忙。

什么是 .net 正则表达式来查找“$”和“<”之间的文本

        string s = "here is my text $$$ Hello World </stop>";
        Match m = Regex.Match(s, "(''$[^<]*)<");
        if (m.Success)
        {
            Console.WriteLine(m.Groups[1].Value);
        }
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));
}

从 VB 代码转换而来,之后没有测试,但应该没问题。

假设示例正确且问题文本错误,您需要:

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

如果情况相反,请尝试以下操作:

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

顺便说一句,使用像这样的工具可以更轻松地回答所有此类问题 在线正则表达式测试器.