读书人

vb6正则表达式如何同时把( )之间和lt;

发布时间: 2012-02-26 20:19:45 作者: rapoo

vb6,正则表达式怎么同时把( )之间和< >之间的文字(并保留它们在原来段落中的顺序)提取出来?
比如一段文字(仅作为举例,实际比这个复杂):
----------------------
guaranteed<索马里>, while reaffirming(美国) its goal of developing nuclear power as a clean energy source.
Hu extends condolences to Myanmar
Chinese President 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 doesn'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 response to an anti-monopoly request from the United States to the World Trade Organization (WTO).
-------------------
我想把所有<>和()中的字符给提取出来(并且要保留它们原先在段落中的顺序,所以不能说分两次单独提取),即结果是:索马里美国利比亚东部usWTO

单独提取()中的文字用regex.Pattern = "(([\s\S]*?))" 就可以了。我现在等于要regex.Pattern = "(([\s\S]*?))" 或者"<([\s\S]*?)>" 。要怎么写呢?我试了regex.Pattern = "(([\s\S]*?))"|"<([\s\S]*?)>"不对。

正则表达式多个pattern的“或者”是怎么写的呢?
多谢!!


[解决办法]
Set reg = New RegExp
reg.Global = True
s = "guaranteed<索马里>, while reaffirming(美国) i{完美}ts "
reg.Pattern = "<(.*?)>|\((.*?)\)|\{(.*?)\}"
For Each r In reg.execute(s)
rv = rv & reg.Replace(r.Value, "$1$2$3") & vbCrLf
Next
MsgBox rv

读书人网 >VB

热点推荐