我有一个像这样的字符串"f_details(\'277095\');">。我只需要得到这个277095部分。我一直在尝试 的变体strPattern = "\'[0-9]\'+",但这要么什么也没找到,要么找到错误的东西。
尽管我面前有一张备忘单,但我不懂正则表达式。已经花了一个小时尝试不同的事情。这个正则表达式会是什么样子?
\n\n这是我用来抓取该网站并获取数据的代码:
\n\nSet objWshShell = Wscript.CreateObject("Wscript.Shell")\nSet IE = CreateObject("internetexplorer.application")\nSet fso = CreateObject("Scripting.FileSystemObject")\n\non error resume next\nFor i=1 To 77 \'77 Counties\n\nIf i=77 Then Exit For\n\nIE.Visible = True\nIE.Navigate "https://lic.ok.gov/PublicPortal/OREC/FindAssociateEntity.jsp"\nDo Until IE.ReadyState = 4: WScript.sleep 15: Loop\n\nDo Until IE.Document.ReadyState = "complete": WScript.sleep 10: Loop\nIE.Document.getElementsByTagName("select")("AddrCountyCode").Value = i\n\nDo Until IE.Document.ReadyState = "complete": WScript.sleep 10: Loop\nFor Each btn In IE.Document.getElementsByTagName("input")\nIf btn.name = "btnSearch" Then btn.Click()\nNEXT\n\nstrPattern = "\'(\\d+)\'"\n\nstrTestString = ie.document.body.innerhtml\n\narrAllMatches = fGetMatches(strPattern, strTestString)\n\nIf UBound(arrAllMatches) <> 0 Then \n\nfilename = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\\License.txt"\n\nset fso = createobject("scripting.filesystemobject")\nset ts = fso.opentextfile(filename,8,true) \nts.write Join(arrAllMatches, vbCrlf)\nts.close \n\nElse\n\nWScript.Echo "-- None Found --"\n\nEnd if\n\nnext\nWscript.echo "DONE!"\n\n\'=====================================================================\nFunction fGetMatches(sPattern, sStr)\nDim regEx, retVal, sMatch, colMatches, temp\nSet regEx = New RegExp \' Create a regular expression.\nregEx.Pattern = sPattern \' Set pattern.\nregEx.IgnoreCase = True \' Set case insensitivity.\nregEx.Global = True \' Set global applicability.\n\nSet colMatches = regEx.Execute(sStr) \' Execute search.\n\nIf colMatches.Count = 0 Then\n temp = Array("")\nElse\n \'# Convert Collection to Array\n For Each sMatch In colMatches\n temp = temp & sMatch & "\xc2\xb6"\n Next\n temp = Left(temp, Len(temp) - 1)\n temp = Split(temp, "\xc2\xb6")\nEnd If\n\nfGetMatches = temp\nEnd Function\nRun Code Online (Sandbox Code Playgroud)\n
'\d+'
Run Code Online (Sandbox Code Playgroud)
只需添加量词\d即可代替'您想要\d重复的内容。
如果(?<=')\d+(?=')你只想获得277095
请参阅演示。
https://regex101.com/r/iS6jF6/6
Dim strRegex as String = "'\d+'"
Dim myRegex As New Regex(strRegex, RegexOptions.Multiline)
Dim strTargetString As String = "f_details('277095');"
For Each myMatch As Match In myRegex.Matches(strTargetString)
If myMatch.Success Then
' Add your code here
End If
Next
Run Code Online (Sandbox Code Playgroud)