首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

求:正则表达式式子里面匹配一个任意字符,比如"整体?线" 如何写?谢谢!

2012-02-01 
求:正则表达式式子里面匹配一个任意字符,比如整体?线 怎么写?多谢!!一段文字(仅为举例,实际比这个复杂):

求:正则表达式式子里面匹配一个任意字符,比如"整体?线" 怎么写?多谢!!
一段文字(仅为举例,实际比这个复杂):
----------------------
guaranteed整体短线索马里>, wh红线ile reaffirming(美国) its goal of developing nuclear power as a clean energy source.
Hu extends condolences to Myanmar
Chinese Pr粗线esident Hu Jintao has delivered a message of condolences (利比亚)to his Myanmar counterpart U Thein Sein over the losses 整体阳线东部>of life and property inflicted by a strong earthquake.
UnionPay network works well: chairman
China doe粗线sn't 整体长线us> need another interbank network for credit cards, said the board chairman of China UnionPay Co Ltd - the country's only credit card network - in re黑线sponse to an anti-monopoly request from the United States to the World Trade Organization (WTO).
-------------------
我想把所有"整体?线"(?可能是短/长/阳...和)和">" 连同 "()"中的字符给提取出来(并且要保留它们原先在段落中的顺序),即结果是:索马里美国利比亚东部usWTO

如果是取"线"和">"之间(连同 "()"中)的字符给取出来的话下面这个举例已经可以.但是我要的是取"整体?线"(?可能是短/长/阳...和)和">" 之间(连同 "()"中)的.正则表达式里面这个"整体?线"要怎么写里面这个"?"通配符呢?
我试了reg.Pattern = "整体?线(.*?)>|\((.*?)\)|\{(.*?)\}"不对.
谢谢!!
----------------------
  Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
s = "guara粗线nteed整体短线索马里>, while reaffirming(美国) i{完美}ts "
reg.Pattern = "线(.*?)>|\((.*?)\)"
For Each r In reg.execute(s)
rv = rv & reg.Replace(r.Value, "$1$2") & vbCrLf
Next
MsgBox rv

[解决办法]

VB code
'此代码由“正则测试工具 v1.1.33”自动生成,请直接调用TestReg过程 
Private Sub TestReg()
  Dim strData As String
  Dim reg As Object
  Dim matchs As Object, match As Object
  Dim s$

  strData = "guaranteed整体短线索马里>, wh红线ile reaffirming(美国) its goal of developing nuclear power as a clean energy source." & vbCrLf & _
      "Hu extends condolences to Myanmar" & vbCrLf & _
      "Chinese Pr粗线esident Hu Jintao has delivered a message of condolences (利比亚)to his Myanmar counterpart U Thein Sein over the losses 整体阳线东部>of life and property inflicted by a strong earthquake." & vbCrLf & _
      "UnionPay network works well: chairman" & vbCrLf & _
      "China doe粗线sn't 整体长线us> need another interbank network for credit cards, said the board chairman of China UnionPay Co Ltd - the country's only credit card network - in re黑线sponse to an anti-monopoly request from the United States to the World Trade Organization (WTO)."

  Set reg = CreateObject("vbscript.regExp")
  reg.Global = True
  reg.IgnoreCase = True
  reg.MultiLine = True
  reg.Pattern = "整体.线(.+?)>|\((.+?)\)"
  Set matchs = reg.Execute(strData)
  For Each match In matchs
    s = s & match.SubMatches(0) & match.SubMatches(1)
  Next
  MsgBox s
End Sub

热点排行