0

I want regex that string, but I really dont know how. I have figured out how I can get the numbers, but not the other strings

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>)"

code

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

Output

1cb07348-34a4-4741-b50f-c41e584370f7

now I want that the output is that

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

what I finished is the first line of the output but I dont know how to regex the other strings

2 Answers2

1

([\w]+-){5} is cleaner to replace what you already did.

\w means [a-zA-Z0-9_].

Then, if your string always has a website preceded and followed by a number of words separated by spaces, you can do this:

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

Ouput

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]);
user11809641
  • 406
  • 3
  • 16
0

I'm guessing that, if our inputs would look like the same, this expression might be somewhat close to what you might have in mind, not sure though:

^(\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+(.*)$

The expression is explained on the top right panel of regex101.com, if you wish to explore/simplify/modify it, and in this link, you can watch how it would match against some sample inputs, if you like.

Reference

Searching for UUIDs in text with regex

Community
  • 1
  • 1
Emma
  • 1
  • 9
  • 28
  • 53
  • I dont understand the result of this the output is the same as the input –  Aug 03 '19 at 18:24