How to conclude number and whitespace from regex matches

Hi, I have this expression to catch all the matches from a string and insert it in a MatchCollection Var.

System.Text.RegularExpressions.Regex.Matches( fullText , “(?<=Name:).*”)

This expression catch all the text in front of “Name:” until a linebreak.
perhaps you realized what I need is a name of a person.

the problem is, sometimes there’s numbers in front of “Name:” and also sometime there’s just whitespace in front of “Name:” which I don’t want it to be identified as a name in my matchCollection var.

what is the exact regex I need?


Please try this

System.Text.RegularExpressions.Regex.Matches( fullText , "(?<=Name:)[a-z A-z]").Cast(Of Regex.Match).Where(function(x) Not String.IsNullOrEmpty(x.value.Trim))


@ibnu.alem Can you show some examples

Try with this regex:

the expression gives error

the number succesfully concluded, but it don’t get the name quite right

@ibnu.alem Can you tell me what should come in this scenario?
Full name or ignore due first space

I need the full name. it’s a worker name and sometimes user miss insert the text source with worker id number, so it becomes “Name: 1987598”

the source string example should be like this:
"Name: Lionel Messi
Id: 9876975

Name: Crishtiano Ronaldo
Id: 9087906


I need all the name in my matchCollection Var so it should be {Crishtiano Ronaldo, Lionel Messi, etc} in the var

@ibnu.alem Ok got it can you share Input string so I can identify what is next after Name so we can restrict on that base

the Input string is exactly like the example I wrote.

Can’t we use a linebreak at the end for restriction instead?


Please use fullname space system.text.RegularExpressions.Regex.Match


now the error says ‘Cast’ is not a member of Match


You use the expression inside cast(of or outside…can you please show it