Function RegTest(ByVal sText As String) As String
'定义正则表达式对象
Dim oRegExp As Object
'定义匹配字符串集合对象
Dim oMatches As Object
'创建正则表达式
Dim a As String
'定义要执行正则查找的文本变量
Set oRegExp = CreateObject("vbscript.regexp")
With oRegExp
'设置是否匹配所有的符合项,True表示匹配所有, False表示仅匹配第一个符合项
.Global = True
'设置是否区分大小写,True表示不区分大小写, False表示区分大小写
.IgnoreCase = True
'设置要查找的字符模式
'.Pattern = "[^x00-xff%&',;=?$x22]"
.Pattern = "[A-Za-z0-9_]+"
'判断是否可以找到匹配的字符,若可以则返回True
MsgBox .Test(sText)
'对字符串执行正则查找,返回所有的查找值的集合,若未找到,则为空
Set oMatches = .Execute(sText)
'把字符串中用正则找到的所有匹配字符替换为其它字符
MsgBox (oMatches(0))
a = oMatches(0)
RegTest = a
MsgBox .Replace(sText, "")
End With
Set oRegExp = Nothing
Set oMatches = Nothing
End Function
Sub a()
Dim Text As String
Text = "这个是pooST11AD:USE=湖综后或者pooDACAO=NOT_USEDH笔记本大家"
ak = RegTest(Text)
MsgBox (ak)
End Sub
import re
import ast
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
d = {}
d["a"] = "use"
d["b"] = "use"
print(d)
check = 'a=="use" and b!="use"'
print(eval(check, {}, d))
checksw = "(defined(a) and b=='use')or(!defined(a) and b=='use')"
pattern = r'!defined\(([^)]+)\)'
matches = re.findall(pattern, checksw)
print(matches)
for m in matches:
checksw = checksw.replace("!defined(" + str(m) + ")", str(m)+"!='NULL'")
print(checksw)
pattern2 = r'defined\(([^)]+)\)'
matches = re.findall(pattern2, checksw)
print(matches)
for m in matches:
checksw = checksw.replace("defined(" + str(m) + ")", str(m)+"=='NULL'")
print(checksw)
print(eval(checksw, {}, d))
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
import re
# 示例文本
text = "Here is a defineVariable_1 and another defineVariable_2."
# 正则表达式模式
pattern = r'define([A-Za-z0-9_]+)'
# 使用findall方法查找所有匹配项
matches = re.findall(pattern, text)
# 打印匹配结果
for match in matches:
print(match)