{"id":1043,"date":"2024-07-03T11:02:44","date_gmt":"2024-07-03T03:02:44","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=1043"},"modified":"2024-07-17T13:35:52","modified_gmt":"2024-07-17T05:35:52","slug":"%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8fregular-express%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=1043","title":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f(Regular Express)\u51fd\u6570\u7cfb\u5217\u4e4b\u4e00"},"content":{"rendered":"\n<p>Public Function ChineseExist(sText) As Boolean &#8216;\u6709\u65e0\u6c49\u5b57<br>Dim oRegExp As Object<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Pattern = &#8220;[\\u4e00-\\u9fa5]&#8221;<br>oRegExp.Global = True<br>ChineseExist = oRegExp.Test(sText)<br>Set oRegExp = Nothing<br>End Function<\/p>\n\n\n\n<p>Public Function NumberSeries(ByVal sText As String) As Variant &#8216;\u63d0\u53d6\u6587\u5b57\u4e2d\u7684\u7eaf\u6570\u5b57,\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de<br>Dim oRegExp As Object<br>Dim oMatches As Object &#8216;\u5339\u914d\u5b57\u7b26\u4e32\u96c6\u5408\u5bf9\u8c61<br>Dim oMatch As Object &#8216;\u5339\u914d\u5b57\u7b26\u4e32<br>Set oRegExp = CreateObject(&#8220;Vbscript.RegExp&#8221;)<br>Dim iCount As Integer<br>Dim TempArray() As Double<br>With oRegExp<br>.Global = True &#8216;True\u8868\u793a\u5339\u914d\u6240\u6709, False\u8868\u793a\u4ec5\u5339\u914d\u7b2c\u4e00\u4e2a\u7b26\u5408\u9879<br>.IgnoreCase = True &#8216;True\u8868\u793a\u4e0d\u533a\u5206\u5927\u5c0f\u5199, False\u8868\u793a\u533a\u5206\u5927\u5c0f\u5199<br>.Pattern = &#8220;([0-9])?<a href=\"[0-9]\">.<\/a>+|([0-9])+&#8221; &#8216;\u5339\u914d\u5b57\u7b26\u6a21\u5f0f(\u4e0d\u8bc6 + &#8211; % \u53f7)<br>Set oMatches = .Execute(sText) &#8216;\u6267\u884c\u6b63\u5219\u67e5\u627e\uff0c\u8fd4\u56de\u6240\u6709\u5339\u914d\u7ed3\u679c\u7684\u96c6\u5408\uff0c\u82e5\u672a\u627e\u5230\uff0c\u5219\u4e3a\u7a7a<br>For Each oMatch In oMatches<br>ReDim Preserve TempArray(0 To iCount)<br>TempArray(iCount) = oMatch.Value<br>iCount = iCount + 1<br>Next<br>End With<br>NumberSeries = TempArray<br>Set oRegExp = Nothing<br>Set oMatches = Nothing<br>End Function<\/p>\n\n\n\n<p>Public Function PureLetter(sText) As Boolean &#8216;\u7eaf\u5b57\u6bcd<br>Dim oRegExp As Object<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Pattern = &#8220;^[A-Za-z]+$&#8221;<br>oRegExp.Global = True<br>PureLetter = oRegExp.Test(sText)<br>Set oRegExp = Nothing<br>End Function<\/p>\n\n\n\n<p>Public Function PureNumber(sText) As Boolean &#8216;\u7eaf\u6570\u5b57<br>Dim oRegExp As Object<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Pattern = &#8220;^[0-9]+$&#8221;<br>oRegExp.Global = True<br>PureNumber = oRegExp.Test(sText)<br>Set oRegExp = Nothing<br>End Function<\/p>\n\n\n\n<p>Public Function ReplaceExp(ByVal sText As String, ByVal sPattern As String, ByVal sNew As String) As String &#8216;\u6587\u5b57\u66ff\u6362<br>Dim oRegExp As Object<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Pattern = sPattern &#8216;\u8bbe\u7f6e\u6a21\u677f\u5c5e\u6027<br>oRegExp.IgnoreCase = True &#8216;\u5ffd\u7565\u5927\u5c0f\u5199<br>oRegExp.Global = True &#8216;\u5339\u914d\u6240\u6709\u641c\u7d22\u9879\u8fd8\u662f\u53ea\u5339\u914d\u7b2c\u4e00\u9879<br>oRegExp.MultiLine = True &#8216;\u662f\u5426\u5728\u591a\u884c\u4e2d\u641c\u7d22<br>ReplaceExp = oRegExp.Replace(sText, sNew)<br>Set oRegExp = Nothing<br>End Function<\/p>\n\n\n\n<p>Public Function IsUrl(ByVal sText As String) As Boolean &#8216;\u5408\u6cd5 Url<br>On Error GoTo ERR_Url<br>Dim oRegExp As Object<br>IsUrl = False<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Pattern = &#8220;(((ht|f)tps?:\/\/)|(www.))([\\w-]+.)+[\\w-:]+(\/[\\w- .\/?%#;&amp;=]*)?&#8221;<br>oRegExp.Global = True<br>IsUrl = oRegExp.Test(sText)<br>Set oRegExp = Nothing<br>ERR_Url:<br>End Function<\/p>\n\n\n\n<p>Public Function IsMail(ByVal sText As String) &#8216;\u5408\u6cd5 eMail<br>On Error GoTo ERR_Mail<br>Dim oRegExp As Object<br>IsMail = False<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Pattern = &#8220;\\w+([-+.]\\w+)<em>@\\w+([-.]\\w+)<\/em>.\\w+([-.]\\w+)*&#8221;<br>oRegExp.Global = True<br>IsMail = oRegExp.Test(sText)<br>Set oRegExp = Nothing<br>ERR_Mail:<br>End Function<\/p>\n\n\n\n<p>Public Function ChineseCount(ByVal sText As String) As Long &#8216;\u6c49\u5b57\u6570\u91cf<br>Dim oRegExp As Object<br>Dim oMatchs As Object<br>Set oRegExp = CreateObject(&#8220;VBScript.RegExp&#8221;)<br>oRegExp.Global = True<br>oRegExp.Pattern = &#8220;[\\u4e00-\\u9fa5]&#8221;<br>Set oMatchs = oRegExp.Execute(sText) &#8216;\u6210\u529f\u5339\u914d\u7684 Match \u5bf9\u8c61\u96c6\u5408<br>ChineseCount = oMatchs.Count<br>Set oRegExp = Nothing<br>End Function<\/p>\n\n\n\n<p>Public Function CheckID(ByVal sText As String, ByVal iFunction As Integer) As String &#8216;\u6838\u67e5 ID, \u5224\u65ad\u8bc1\u4ef6\u53f7\u7801\u662f\u5426\u6b63\u786e, \u6216\u63d0\u53d6\u51fa\u751f\u65e5\u671f,\u6216\u8fd4\u56de\u6027\u522b, \u6216\u8fd4\u56de\u5e74\u9f84<br>Dim oItem As Object<br>Dim iSum As Integer<br>Dim FactorArray As Variant, CRCArray As Variant<br>Dim I As Integer<br>Dim sBirthDate As String<br>FactorArray = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2) &#8216;\u8eab\u4efd\u8bc1\u53f7\u52a0\u6743\u56e0\u5b50<br>CRCArray = Array(&#8220;1&#8221;, &#8220;0&#8221;, &#8220;X&#8221;, &#8220;9&#8221;, &#8220;8&#8221;, &#8220;7&#8221;, &#8220;6&#8221;, &#8220;5&#8221;, &#8220;4&#8221;, &#8220;3&#8221;, &#8220;2&#8221;) &#8216;\u6700\u540e\u4e00\u4f4d\u6709\u6548\u6821\u9a8c\u4f4d<br>If Len(sText) = 18 Then &#8216;\u5224\u65ad\u662f\u5426\u4e3a18\u4f4d<br>Set oRegExp = CreateObject(&#8220;Vbscript.RegExp&#8221;)<br>oRegExp.Pattern = &#8220;[A-Za-z0-9]{1}&#8221; &#8216;\u5e94\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u62c6\u621018\u4e2a1\u4f4d\u6570\uff0c\u6b64\u6b65\u53ef\u4ee5\u5e94\u7528mid\u51fd\u6570\uff0c\u4f46\u6b63\u5219\u8868\u8fbe\u5f0f\u4f1a\u6548\u7387\u4f1a\u66f4\u9ad8<br>oRegExp.Global = True<br>Set oItem = oRegExp.Execute(sText)<br>For I = 0 To 16<br>iSum = oItem(I) * FactorArray(I) + iSum<br>Next I<br>If CRCArray(iSum Mod 11) = UCase(oItem(17)) Then<br>Select Case iFunction<br>Case 1 &#8216;\u5224\u65ad\u8bc1\u4ef6\u53f7\u7801\u662f\u5426\u6b63\u786e<br>CheckID = &#8220;True&#8221;<br>Case 2 &#8216;\u63d0\u53d6\u51fa\u751f\u65e5\u671f<br>CheckID = Format(Mid(sText, 7, 8), &#8220;0-00-00&#8221;)<br>Case 3 &#8216;\u8fd4\u56de\u6027\u522b<br>If oItem(16) Mod 2 = 0 Then CheckID = &#8220;Female&#8221; Else CheckID = &#8220;Male&#8221;<br>Case 4 &#8216;\u8fd4\u56de\u5468\u5c81\u5e74\u9f84<br>sBirthDate = Format(Mid(sText, 7, 8), &#8220;0-00-00&#8221;)<br>If Month(sBirthDate) &lt; Month(Date) Then CheckID = DateDiff(&#8220;yyyy&#8221;, sBirthDate, Date) ElseIf Month(sBirthDate) &gt; Month(Date) Then<br>CheckID = DateDiff(&#8220;yyyy&#8221;, sBirthDate, Date) &#8211; 1<br>ElseIf Day(sBirthDate) &gt; Day(Date) Then<br>CheckID = DateDiff(&#8220;yyyy&#8221;, sBirthDate, Date) &#8211; 1<br>Else<br>CheckID = DateDiff(&#8220;yyyy&#8221;, sBirthDate, Date)<br>End If<br>End Select<br>Else<br>CheckID = &#8220;False&#8221; &#8216;\u9519\u8bef<br>End If<br>Else<br>CheckID = &#8220;Invalid&#8221; &#8216;\u975e\u4e2d\u56fd\u5c45\u6c11\u8eab\u4efd\u8bc1<br>End If<br>End Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Public Function ChineseExist(sText) As Boolean &#8216;\u6709 &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=1043\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u6b63\u5219\u8868\u8fbe\u5f0f(Regular Express)\u51fd\u6570\u7cfb\u5217\u4e4b\u4e00\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-1043","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1043"}],"version-history":[{"count":8,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1043\/revisions"}],"predecessor-version":[{"id":1313,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1043\/revisions\/1313"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}