Regex VB.net如何拆分此文件?

Regex VB.net如何拆分此文件?,regex,vb.net,string,split,Regex,Vb.net,String,Split,我试图在VB.net所有者id中拆分此代码,这是数据字符串 yt.setConfig('DISTILLER_CONFIG', {"signin_url": "https:\/\/accounts.google.com\/ServiceLogin?hl=da\u0026continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26feature%3Dcomments%26

我试图在VB.net所有者id中拆分此代码,这是数据字符串

yt.setConfig('DISTILLER_CONFIG', {"signin_url": "https:\/\/accounts.google.com\/ServiceLogin?hl=da\u0026continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26feature%3Dcomments%26hl%3Dda%26next%3D%252Fall_comments%253Fv%253DZNW_uQaYfB0\u0026uilel=3\u0026passive=true\u0026service=youtube", "host_override": "https:\/\/plus.googleapis.com", "query": "http:\/\/www.youtube.com\/watch?v=ZNW_uQaYfB0", "channel_id": "UCe4LM_eKc9ywRmVuBm5pjQg", "first_time_comment_promo": false, "privacy_setting": "PUBLIC", "visible": true, "pinned_activity": null, "page_size": 100, "owner_id": "e4LM_eKc9ywRmVuBm5pjQg", "reauth": false, "video_id": "ZNW_uQaYfB0"});
到目前为止,我已经尝试过这个代码,但它不起作用。已声明所有者id字符串

owner_id = (Split(data, """owner_id"": """)(1).Split("""")(0)
但它不起作用

编辑:

如何将JSON选择为要从这些脚本中拆分的字符串

我建议使用正则表达式:

但只有当您真的想要解析这个单一的键/值对时。如果需要提取更多内容,我宁愿考虑提取JSON并以正常方式反序列化它

工作示例:

Dim regex As Regex = New Regex("""owner_id"": ""([\d\w]*)""")
Dim match As Match = regex.Match("...here your string...")
If match.Success Then
   Console.WriteLine(match.Groups(1).Value)
End If
如果有像yt.Config这样的多个部分。。。您可以将所需的一个标识符包含到正则表达式中,例如:

Dim regex As Regex = New Regex("yt.setConfig\('DISTILLER_CONFIG'.*""owner_id"": ""([\d\w]*)""")

这是JSON,字符串拆分这不是一个好主意,但您应该使用以下命令将JSON反序列化为类对象:

Public Class DistillerConfigResults
    Public Property DISTILLER_CONFIG As DistillerConfig
End Class

Public Class DistillerConfig
    Public Property signin_url As String
    Public Property host_override As String
    Public Property query As String
    Public Property signin_url As String
    Public Property channel_id As String
    Public Property first_time_comment_promo As Boolean
    Public Property privacy_setting As String
    Public Property visible As Boolean
    Public Property pinned_activity As Object
    Public Property page_size As Integer
    Public Property owner_id As String
    Public Property reauth As Boolean
    Public Property video_id As String
End Class
Dim a As DistillerConfigResults = JsonConvert.DeserializeObject(Of DistillerConfigResults)(jsonString)
现在可以将JSON反序列化到类对象中,如下所示:

Public Class DistillerConfigResults
    Public Property DISTILLER_CONFIG As DistillerConfig
End Class

Public Class DistillerConfig
    Public Property signin_url As String
    Public Property host_override As String
    Public Property query As String
    Public Property signin_url As String
    Public Property channel_id As String
    Public Property first_time_comment_promo As Boolean
    Public Property privacy_setting As String
    Public Property visible As Boolean
    Public Property pinned_activity As Object
    Public Property page_size As Integer
    Public Property owner_id As String
    Public Property reauth As Boolean
    Public Property video_id As String
End Class
Dim a As DistillerConfigResults = JsonConvert.DeserializeObject(Of DistillerConfigResults)(jsonString)

这看起来像是JSON——为什么不使用JSON转换器或反序列化器呢?至少有两个用于.NET的JSON转换器或反序列化器。。我之所以选择这个部分,是因为我试图拆分的是其中的数据。好吧,这是可行的,但我如何选择特定的JSON字符串,因为这里有多个名为yt.setConfigJSON的字符串。。我将用完整的html代码编辑该线程,不过谢谢@安德斯,我更新了我的答案,希望能给你一个线索