Regex expression for hashtag and set number of digits followed by known string?

Viewed 29

I have the following text that I would like to find with a regular expression starting with the # and ending with ____, with the only known string being the 2nd line (long string of numbers and letters). I've tried #^.{1,20}$\nbd11bf73-b47b-4ab6-986b-f96d641ad2a8.*____ and various combinations of this without luck. Can anyone give me a pointer as to where I'm going wrong? Thanks

#140213696
bd11bf73-b47b-4ab6-986b-f96d641ad2a8
Name: admin test
Phone: 
Due: £0

1 Adult
Surf All Day: No /  / 


____
1 Answers

You could use a named group to get the wanted value:

#.{1,}\n(?<id>.{1,})\r

I don't know what language you are using but here is a code sample in c# to retrive this value from id group:

var yourString = @"#140213696
bd11bf73-b47b-4ab6-986b-f96d641ad2a8
Name: admin test
Phone: 
Due: £0

1 Adult
Surf All Day: No /  / 


____";

var matches  = Regex.Matches(yourString, @"#.{1,}\n(?<id>.{1,})\r");

var ids = new List<string>();
foreach (Match match in matches)
{
    ids.Add(match.Groups["id"].Value);            
}
Related