1 重點(diǎn)內容
01 正則表達式文本
myreg.pattern=".*[^學(xué)歷規劃師]:\s+.*"
02 執行語(yǔ)句
regexp.execute(s)
使用regexp對象那個(gè)已經(jīng)設置好的表達式(pattern屬性)在字符竄s中查找符合t條件的文本
03 替換
regexp.replace(s,r)并未修改原文本是,而是將替換后的節骨作為一個(gè)新的字符竄
cells(i,2)=myreg.(s,replace,“$1:$2“)
#$n 代表din個(gè)圓括號中捕獲的內容
2 應用案例
- option explicit
- Sub replacedemo()
- dim i&,s$
- dim myreg as Object
- dim myMatches as Object,mymatch as object
- '將內容賦值變量
- s=range("g2").value
- ‘創(chuàng )建一個(gè)regexp類(lèi)型對象,可用于調用處理正則表達式
- '
- set myReg= Createobject ("Vbscript.regexp")
- '獲取正則表達式文本
- myseg.pattern="(.*)[^學(xué)歷規劃師]:(\s+).*"
- # 導出所有符合表達式的內容:
- myReg.Global=true
- # 應用execute方法執行表達式得到數組
- set ymatches=myreg.execute(s)
- # 將括號內的內容進(jìn)行替換
- $n 只輸出對應的括號內的內容
- cell(2,2)myreg.replace(s,"$1:$2")
- #遍歷matches里邊所有符合表達式的內容
- for each mymatche in mymatches
- cells(i,1)=myMatche.submatches(0)
- cells(i,2)=myMatche.submatches(0)
- i=i+1
- next mymatc
- end sub

