Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在正则表达式中获取所有后面的字符_Regex_Vb.net - Fatal编程技术网

Regex 在正则表达式中获取所有后面的字符

Regex 在正则表达式中获取所有后面的字符,regex,vb.net,Regex,Vb.net,我需要一个按钮,用于将单词从:字符的左侧和右侧分开。我知道如何在:之前获得所有,但在:之后如何获得所有 我的代码: TextBox1.Text = System.IO.File.ReadAllText(OpenFileDialog1.FileName) Dim findtext2 As String = "(.*?)(?=:)" 'Gets all before ":" Dim myregex2 As String = TextBox1.Text Dim doregex2 As MatchCol

我需要一个按钮,用于将单词从
字符的左侧和右侧分开。我知道如何在
之前获得所有,但在
之后如何获得所有

我的代码:

TextBox1.Text = System.IO.File.ReadAllText(OpenFileDialog1.FileName)
Dim findtext2 As String = "(.*?)(?=:)" 'Gets all before ":"
Dim myregex2 As String = TextBox1.Text
Dim doregex2 As MatchCollection = Regex.Matches(myregex2, findtext2)
Dim matches2 As String = ""
For Each match2 As Match In doregex2
    matches2 = matches2 + match2.ToString + Environment.NewLine
Next
MsgBox(matches2)

我尝试使用
Dim findtext2 As String=“(?=:)(.*)”
,但它不起作用。

如果知道字符串将包含冒号,可以使用调用而不是正则表达式来获取所需的节:

If TextBox1.Text.Contains(":") Then
    ' Split using the colon '
    Dim sections = TextBox1.Text.Split(":")
    ' Get the first part '
    Dim before = sections(0)
    ' Get the second part '
    Dim after = sections(1)
End If

如果知道字符串将包含冒号,则可以使用调用而不是正则表达式来获取所需的部分:

If TextBox1.Text.Contains(":") Then
    ' Split using the colon '
    Dim sections = TextBox1.Text.Split(":")
    ' Get the first part '
    Dim before = sections(0)
    ' Get the second part '
    Dim after = sections(1)
End If

正则表达式应该是
(?是的,它工作得很好,谢谢!正则表达式应该是
(?是的,它工作得很好,谢谢!是的,它可以处理简单的列表(如书籍:pencil)。我已经在电子邮件列表中试过了(example@domain.com:password),它将获得“password”,但在下一行还会收到电子邮件(没有密码)如果你计划每个行上的内容彼此独立,那么你可以考虑使用< <代码>文件> Read Link()/<代码>方法。然后,你可以简单地遍历每一行并抓住你的内容,如果这是有意义的。是的,我认为这是可行的,但是对于ReGEX <代码>来说,这是非常简单的(至少对我来说)。(?是的,使用简单的列表(如书:铅笔)。我已经用电子邮件列表尝试过了(example@domain.com它会得到“密码”,但也会在下一行(没有密码)下发电子邮件。有什么想法吗?你可能想考虑使用<代码>文件。
方法,如果您计划每一行上的内容彼此独立。然后您可以简单地迭代每一行并获取您的内容,如果这有意义的话。是的,我认为这会起作用,但使用regex
(?