如何正则表达式那种字符串

how to regex that kind of string

我想要那个字符串的正则表达式,但我真的不知道怎么做。我已经弄清楚如何获取数字,但不是其他字符串

string text = "1cb07348-34a4-4741-b50f-c41e584370f7 Youtuber https://youtube.com/lol love youtube";
string regexstring = "[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]*(?<id>)"

代码

Match m = Regex.Match(text, regexstring);
if(m.Success)
   Console.WriteLine(m.Groups[0]);

输出

1cb07348-34a4-4741-b50f-c41e584370f7

现在我希望输出是

1cb07348-34a4-4741-b50f-c41e584370f7
Youtuber
https://youtube.com/lol
love youtube

我完成的是输出的第一行,但我不知道如何对其他字符串进行正则表达式

([\w]+-){5} 更干净,可以替换您已经做过的。

\w 表示 [a-zA-Z0-9_].

然后,如果你的字符串总是有一个网站前后由空格分隔的多个单词,你可以这样做:

string regexstring = "((\w*-){4})(\w*) (.+?)[A-Za-z]?(https://[^ ]+?) (.+)";

输出

Match m = Regex.Match(text, regexstring);
if(m.Success)
    Console.WriteLine(m.Groups[1] + "" + m.Groups[2] + "" + m.Groups[3] + "\n" + m.Groups[4] + "\n" + m.Groups[5] + "\n" + m.Groups[6]);

我猜,如果我们的输入看起来一样,这个表达式可能有点接近您的想法,但不确定:

^(\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)\s+(.*?)\s+[A-Z](https?:\/\/\S+)\s+(.*)$

表达式在 regex101.com, if you wish to explore/simplify/modify it, and in this link 的右上面板进行了解释,如果您愿意,您可以观察它如何与一些示例输入匹配。

参考

Searching for UUIDs in text with regex