例如有不确定多少行的一个文件,内容如下
lkdsk2098423(aaafa)fdsflk
38490832(bdd)klj392
Kds9fsdf(894375)
l00939u47(kdii)
....
...
....
在text里面输入带有回车符的文本后,点击Command,就会留下每行括号内的内容(不带括号的)!
aaafa
bdd
894375
kdii
.....
....
....
lkdsk2098423(aaafa)fdsflk
38490832(bdd)klj392
Kds9fsdf(894375)
l00939u47(kdii)
....
...
....
在text里面输入带有回车符的文本后,点击Command,就会留下每行括号内的内容(不带括号的)!
aaafa
bdd
894375
kdii
.....
....
....
dim strArry() as string
dim strT as string
dim i as long
dim j as long
dim n as long
strArry = split(text1. text,vbcrlf)
text1. text = ""
for i =0 to ubound(strArry)
strT = strArry(i)
j=instr(strT,"(")
n=instr(strT,")")
text1. text =text1. text & mid(strT,j ,n-j )
next
(aaafa(bdd(894375(kdii
左面的括号没有去掉,而且把火车符给去掉了
麻烦再改一改
Private Sub TestReg()
Dim strData As String
Dim reg As Object
Dim matchs As Object, match As Object strData = "lkdsk2098423(aaafa)fdsflk" & vbCrLf & _
"38490832(bdd)klj392" & vbCrLf & _
"Kds9fsdf(894375)" & vbCrLf & _
"l00939u47(kdii)" 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
'Debug.Print match.Value
Debug.Print match.SubMatches(0)
Next
End Sub
dim strArry() as string
dim strT as string
dim i as long
strArry = split(text1. text,vbcrlf)
text1. text = ""
for i =0 to ubound(strArry)
strT = strArry(i)
text1. text =text1. text & split(split(strT,"(")(1),")")(0)
next
dim strT as string
dim i as long
dim j as long
dim n as long
strArry = split(text1. text,vbcrlf)
text1. text = ""
for i =0 to ubound(strArry)
strT = strArry(i)
j=instr(strT,"(")
n=instr(strT,")")
text1. text =text1. text & mid(strT,j+1 ,n-j ) & vbCrlf
next i