以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  正则表达式提取问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=188937)

--  作者:benwong2015
--  发布时间:2023/11/1 10:28:00
--  正则表达式提取问题
Dim txt As String = "+  1.2990g"
Dim pattern As String = "+(.*?)g"
Dim str = System.Text.RegularExpressions.Regex.Matches(txt, pattern, "")
Output.Show(str)

请问要提取+与g之间的所有字符,提示错误,请问如何修改?

--  作者:有点蓝
--  发布时间:2023/11/1 10:38:00
--  
Dim txt As String = "+  1.2990g"
Dim pattern As String = "(?<=\\+).*?(?=g)"
Dim rgx = New System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
For Each match As System.Text.RegularExpressions.Match In rgx.Matches(txt)
    Output.Show(match.Value)
Next