Regular expression

I'm looking for a regular expression to match the following:

source: "blablabla,"name":"James Smith","Age":"
Text to extract : James Smith

I need something to check for text in the middle of "name":" and ",Age":

Can anyone help please?
IAJWDDIYAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi IAJWDDIY;

This regular expression pattern should do what you need->     .*?\x22name\x22:\x22([^\x22]+)

The \x22 in the pattern is the regular expression meta character for the " in the input string.  I use \x22 so that you do not need to double up on the " character in the pattern when using it in the program.

Fernando
Imports System.Text.RegularExpressions
 
    ' Test string
    Dim input As String = "blablabla,""name"":""James Smith"",""Age"":"
 
    ' Regex patern
    Dim pattern As String = ".*?\x22name\x22:\x22([^\x22]+)"
    Dim output As String = Regex.Match(input, pattern).Groups(1).Value
 
    ' Display results which is in this case James Smith
    MessageBox.Show(output)

Open in new window

0
 
ubigCommented:
This should do:
.*?,"name":"(.*?)","Age":
0
 
IAJWDDIYAuthor Commented:
Thank you
0
 
b0lsc0ttIT ManagerCommented:
I am a fan of expressions and would've suggested the method FernandoSoto suggested above.  However with the format of the string and what you want I would in this case suggest 2 "splits" and a little script.  If you can use a scripting language it would probably be more efficient than using a regex object.

First split on the : character and get the 2nd item in the array.  That will be the "James Smith","Age" part.  Next split on the , character and get the first item.  That would leave you with "James Smith" and you can just remove the double quotes.

Just an alternative if your source is like you described above.  Let me know if you have a question.

bol
0
All Courses

From novice to tech pro — start learning today.