⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00000002.htm

📁 一份很好的linux入门资料
💻 HTM
📖 第 1 页 / 共 4 页
字号:
Escapes.&nbsp;&nbsp;<BR>&nbsp;<BR>Part&nbsp;2.&nbsp;Regular&nbsp;Expressions&nbsp;in&nbsp;Tcl&nbsp;8.1&nbsp;<BR>Tcl&nbsp;8.1&nbsp;regular&nbsp;expressions&nbsp;are&nbsp;basically&nbsp;a&nbsp;superset&nbsp;of&nbsp;8.0&nbsp;REs.&nbsp;This&nbsp;&nbsp;<BR>howto&nbsp;document&nbsp;has&nbsp;an&nbsp;overview&nbsp;of&nbsp;the&nbsp;new&nbsp;features.&nbsp;Please&nbsp;see&nbsp;the&nbsp;&nbsp;<BR>re_syntax(n)&nbsp;reference&nbsp;page&nbsp;for&nbsp;exact&nbsp;semantics&nbsp;and&nbsp;more&nbsp;details.&nbsp;&nbsp;<BR>&nbsp;<BR>Non-Greedy&nbsp;Quantifiers&nbsp;<BR>A&nbsp;quantifier&nbsp;specifies&nbsp;&quot;how&nbsp;many.&quot;&nbsp;For&nbsp;example,&nbsp;the&nbsp;quantifier&nbsp;*&nbsp;in&nbsp;&nbsp;<BR>the&nbsp;RE&nbsp;z*&nbsp;matches&nbsp;zero&nbsp;or&nbsp;more&nbsp;zs.&nbsp;By&nbsp;default,&nbsp;regular&nbsp;expression&nbsp;&nbsp;<BR>quantifiers&nbsp;are&nbsp;greedy:&nbsp;they&nbsp;match&nbsp;as&nbsp;much&nbsp;text&nbsp;as&nbsp;they&nbsp;can.&nbsp;Tcl&nbsp;8.1&nbsp;REs&nbsp;<BR>&nbsp;also&nbsp;have&nbsp;non-greedy&nbsp;quantifiers,&nbsp;which&nbsp;match&nbsp;the&nbsp;least&nbsp;text&nbsp;they&nbsp;can.&nbsp;<BR>&nbsp;To&nbsp;make&nbsp;a&nbsp;non-greedy&nbsp;quantifier,&nbsp;add&nbsp;a&nbsp;question&nbsp;mark&nbsp;(?)&nbsp;at&nbsp;the&nbsp;end.&nbsp;&nbsp;<BR>Let's&nbsp;start&nbsp;by&nbsp;storing&nbsp;some&nbsp;HTML&nbsp;text&nbsp;in&nbsp;a&nbsp;variable,&nbsp;then&nbsp;using&nbsp;two&nbsp;&nbsp;<BR>regexp&nbsp;commands&nbsp;to&nbsp;match&nbsp;it.&nbsp;The&nbsp;first&nbsp;RE&nbsp;is&nbsp;greedy,&nbsp;and&nbsp;the&nbsp;second&nbsp;is&nbsp;&nbsp;<BR>non-greedy:&nbsp;&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>%&nbsp;set&nbsp;x&nbsp;{&lt;EM&gt;He&lt;/EM&gt;&nbsp;sits,&nbsp;but&nbsp;&lt;EM&gt;she&lt;/EM&gt;&nbsp;stands.}&nbsp;<BR>&lt;EM&gt;He&lt;/EM&gt;&nbsp;sits,&nbsp;but&nbsp;&lt;EM&gt;she&lt;/EM&gt;&nbsp;stands.&nbsp;<BR>%&nbsp;regexp&nbsp;{&lt;EM&gt;.*&lt;/EM&gt;}&nbsp;$x&nbsp;match;&nbsp;set&nbsp;match&nbsp;<BR>&lt;EM&gt;He&lt;/EM&gt;&nbsp;sits,&nbsp;but&nbsp;&lt;EM&gt;she&lt;/EM&gt;&nbsp;<BR>%&nbsp;regexp&nbsp;{&lt;EM&gt;.*?&lt;/EM&gt;}&nbsp;$x&nbsp;match;&nbsp;set&nbsp;match&nbsp;<BR>&lt;EM&gt;He&lt;/EM&gt;&nbsp;<BR>&nbsp;<BR>The&nbsp;first&nbsp;RE&nbsp;&lt;EM&gt;.*&lt;/EM&gt;&nbsp;is&nbsp;&quot;greedy.&quot;&nbsp;It&nbsp;matches&nbsp;from&nbsp;the&nbsp;first&nbsp;&lt;EM&gt;&nbsp;&nbsp;<BR>to&nbsp;the&nbsp;last&nbsp;&lt;/EM&gt;.&nbsp;The&nbsp;second&nbsp;RE&nbsp;&lt;EM&gt;.*?&lt;/EM&gt;,&nbsp;with&nbsp;a&nbsp;question&nbsp;mark&nbsp;&nbsp;<BR>(?)&nbsp;after&nbsp;the&nbsp;*&nbsp;quantifier,&nbsp;is&nbsp;non-greedy:&nbsp;it&nbsp;matches&nbsp;as&nbsp;little&nbsp;text&nbsp;&nbsp;<BR>as&nbsp;possible&nbsp;after&nbsp;the&nbsp;first&nbsp;&lt;EM&gt;.&nbsp;Could&nbsp;you&nbsp;write&nbsp;a&nbsp;greedy&nbsp;RE&nbsp;that&nbsp;works&nbsp;<BR>&nbsp;like&nbsp;the&nbsp;non-greedy&nbsp;version?&nbsp;It&nbsp;isn't&nbsp;easy!&nbsp;A&nbsp;greedy&nbsp;RE&nbsp;like&nbsp;&nbsp;<BR>&lt;EM&gt;[^&lt;]*&lt;/EM&gt;&nbsp;would&nbsp;do&nbsp;it&nbsp;in&nbsp;this&nbsp;case&nbsp;--&nbsp;but&nbsp;it&nbsp;wouldn't&nbsp;work&nbsp;if&nbsp;there&nbsp;<BR>&nbsp;were&nbsp;other&nbsp;HTML&nbsp;tags&nbsp;(with&nbsp;a&nbsp;&lt;&nbsp;character)&nbsp;between&nbsp;the&nbsp;pair&nbsp;of&nbsp;&lt;EM&gt;&nbsp;tags&nbsp;<BR>&nbsp;in&nbsp;the&nbsp;$x&nbsp;string.&nbsp;&nbsp;<BR>Here&nbsp;are&nbsp;a&nbsp;new&nbsp;string&nbsp;and&nbsp;another&nbsp;pair&nbsp;of&nbsp;REs&nbsp;to&nbsp;match&nbsp;it:&nbsp;&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>%&nbsp;set&nbsp;y&nbsp;{123zzz456}&nbsp;<BR>123zzz456&nbsp;<BR>%&nbsp;regexp&nbsp;{3z*}&nbsp;$y&nbsp;match;&nbsp;set&nbsp;match&nbsp;<BR>3zzz&nbsp;<BR>%&nbsp;regexp&nbsp;{3z*?}&nbsp;$y&nbsp;match;&nbsp;set&nbsp;match&nbsp;<BR>3&nbsp;<BR>&nbsp;<BR>The&nbsp;greedy&nbsp;RE&nbsp;3z*&nbsp;matches&nbsp;all&nbsp;the&nbsp;zs&nbsp;it&nbsp;can&nbsp;(three)&nbsp;under&nbsp;its&nbsp;&quot;zero&nbsp;or&nbsp;&nbsp;<BR>more&quot;&nbsp;rule.&nbsp;The&nbsp;non-greedy&nbsp;RE&nbsp;3z*?&nbsp;matches&nbsp;just&nbsp;3&nbsp;because&nbsp;it&nbsp;matches&nbsp;the&nbsp;<BR>&nbsp;fewest&nbsp;zs&nbsp;it&nbsp;can&nbsp;under&nbsp;its&nbsp;&quot;zero&nbsp;or&nbsp;more&quot;&nbsp;rule.&nbsp;&nbsp;<BR>To&nbsp;review,&nbsp;the&nbsp;greedy&nbsp;quantifiers&nbsp;from&nbsp;Tcl&nbsp;8.0&nbsp;are:&nbsp;*,&nbsp;+,&nbsp;and&nbsp;?.&nbsp;So&nbsp;&nbsp;<BR>the&nbsp;non-greedy&nbsp;quantifiers&nbsp;(added&nbsp;in&nbsp;Tcl&nbsp;8.1)&nbsp;are:&nbsp;*?,&nbsp;+?,&nbsp;and&nbsp;??.&nbsp;Tcl&nbsp;&nbsp;<BR>8.1&nbsp;also&nbsp;has&nbsp;the&nbsp;new&nbsp;quantifiers&nbsp;{m},&nbsp;{m,},&nbsp;and&nbsp;{m,n},&nbsp;as&nbsp;well&nbsp;as&nbsp;the&nbsp;&nbsp;<BR>non-greedy&nbsp;versions&nbsp;{m}?,&nbsp;{m,}?,&nbsp;and&nbsp;{m,n}?.&nbsp;The&nbsp;section&nbsp;on&nbsp;bounds&nbsp;&nbsp;<BR>explains&nbsp;--&nbsp;and&nbsp;has&nbsp;more&nbsp;examples&nbsp;of&nbsp;non-greedy&nbsp;matching.&nbsp;&nbsp;<BR>&nbsp;<BR>Backslash&nbsp;Escapes&nbsp;<BR>A&nbsp;backslash&nbsp;(\)&nbsp;disables&nbsp;the&nbsp;metacharacter&nbsp;after&nbsp;it.&nbsp;For&nbsp;example,&nbsp;a\*&nbsp;&nbsp;<BR>matches&nbsp;the&nbsp;character&nbsp;a&nbsp;followed&nbsp;by&nbsp;a&nbsp;literal&nbsp;asterisk&nbsp;(*)&nbsp;character.&nbsp;In&nbsp;<BR>&nbsp;Tcl&nbsp;8.0&nbsp;and&nbsp;before,&nbsp;it&nbsp;was&nbsp;legal&nbsp;to&nbsp;put&nbsp;a&nbsp;backslash&nbsp;before&nbsp;a&nbsp;&nbsp;<BR>non-metacharacter&nbsp;--&nbsp;for&nbsp;instance,&nbsp;regexp&nbsp;{\p}&nbsp;matched&nbsp;the&nbsp;character&nbsp;p.&nbsp;<BR>&nbsp;(Note&nbsp;that&nbsp;regexp&nbsp;{\n}&nbsp;matched&nbsp;the&nbsp;character&nbsp;n,&nbsp;which&nbsp;was&nbsp;a&nbsp;source&nbsp;of&nbsp;&nbsp;<BR>confusion.&nbsp;To&nbsp;get&nbsp;a&nbsp;newline&nbsp;character&nbsp;into&nbsp;an&nbsp;RE&nbsp;before&nbsp;version&nbsp;8.1,&nbsp;you&nbsp;<BR>&nbsp;had&nbsp;to&nbsp;write&nbsp;regexp&nbsp;&quot;\n&quot;&nbsp;so&nbsp;Tcl&nbsp;processing&nbsp;inside&nbsp;double&nbsp;quotes&nbsp;would&nbsp;&nbsp;<BR>convert&nbsp;the&nbsp;\n&nbsp;to&nbsp;a&nbsp;newline.)&nbsp;&nbsp;<BR>The&nbsp;Tcl&nbsp;8.1&nbsp;regular&nbsp;expression&nbsp;engine&nbsp;interprets&nbsp;backslash&nbsp;escapes&nbsp;&nbsp;<BR>itself.&nbsp;So&nbsp;now&nbsp;regexp&nbsp;{\n}&nbsp;matches&nbsp;a&nbsp;newline,&nbsp;not&nbsp;the&nbsp;character&nbsp;n.&nbsp;REs&nbsp;&nbsp;<BR>are&nbsp;simpler&nbsp;to&nbsp;write&nbsp;in&nbsp;8.1&nbsp;because&nbsp;of&nbsp;this.&nbsp;(You&nbsp;can&nbsp;still&nbsp;write&nbsp;regexp&nbsp;<BR>&nbsp;&quot;\n&quot;&nbsp;--&nbsp;and&nbsp;let&nbsp;Tcl&nbsp;conversion&nbsp;happen&nbsp;inside&nbsp;the&nbsp;double&nbsp;quotes&nbsp;--&nbsp;so&nbsp;&nbsp;<BR>most&nbsp;old&nbsp;code&nbsp;will&nbsp;still&nbsp;work.)&nbsp;&nbsp;<BR>&nbsp;<BR>One&nbsp;of&nbsp;the&nbsp;most&nbsp;important&nbsp;changes&nbsp;in&nbsp;8.1&nbsp;is&nbsp;that&nbsp;a&nbsp;backslash&nbsp;inside&nbsp;a&nbsp;&nbsp;<BR>bracket&nbsp;expression&nbsp;is&nbsp;treated&nbsp;as&nbsp;the&nbsp;start&nbsp;of&nbsp;an&nbsp;escape.&nbsp;In&nbsp;8.0&nbsp;and&nbsp;&nbsp;<BR>before,&nbsp;a&nbsp;backslash&nbsp;inside&nbsp;brackets&nbsp;was&nbsp;treated&nbsp;as&nbsp;a&nbsp;literal&nbsp;backslash&nbsp;&nbsp;<BR>character.&nbsp;For&nbsp;example,&nbsp;in&nbsp;8.0&nbsp;and&nbsp;before,&nbsp;regexp&nbsp;{[a\n]}&nbsp;would&nbsp;match&nbsp;&nbsp;<BR>the&nbsp;characters&nbsp;a,&nbsp;\,&nbsp;or&nbsp;n.&nbsp;But&nbsp;in&nbsp;8.1,&nbsp;regexp&nbsp;{[a\n]}&nbsp;would&nbsp;match&nbsp;the&nbsp;&nbsp;<BR>characters&nbsp;a&nbsp;or&nbsp;newline&nbsp;(because&nbsp;\n&nbsp;is&nbsp;the&nbsp;backslash&nbsp;escape&nbsp;for&nbsp;&nbsp;<BR>&quot;newline&quot;).&nbsp;&nbsp;<BR>&nbsp;<BR>Tcl&nbsp;8.1&nbsp;has&nbsp;also&nbsp;added&nbsp;many&nbsp;new&nbsp;backslash&nbsp;escapes.&nbsp;For&nbsp;instance,&nbsp;\d&nbsp;&nbsp;<BR>matches&nbsp;a&nbsp;digit.&nbsp;Some&nbsp;of&nbsp;these&nbsp;are&nbsp;listed&nbsp;below,&nbsp;and&nbsp;the&nbsp;re_syntax(n)&nbsp;&nbsp;<BR>reference&nbsp;page&nbsp;has&nbsp;the&nbsp;whole&nbsp;list.&nbsp;&nbsp;<BR>&nbsp;<BR>In&nbsp;Tcl&nbsp;8.1&nbsp;regular&nbsp;expressions&nbsp;(but&nbsp;not&nbsp;in&nbsp;other&nbsp;parts&nbsp;of&nbsp;the&nbsp;language),&nbsp;<BR>&nbsp;it's&nbsp;illegal&nbsp;to&nbsp;use&nbsp;a&nbsp;backslash&nbsp;before&nbsp;a&nbsp;non-metacharacter&nbsp;unless&nbsp;it&nbsp;&nbsp;<BR>makes&nbsp;a&nbsp;valid&nbsp;escape.&nbsp;So&nbsp;regexp&nbsp;{\p}&nbsp;is&nbsp;now&nbsp;an&nbsp;error.&nbsp;If&nbsp;you&nbsp;have&nbsp;code&nbsp;&nbsp;<BR>that&nbsp;(for&nbsp;some&nbsp;bizarre&nbsp;reason)&nbsp;has&nbsp;regular&nbsp;expressions&nbsp;with&nbsp;a&nbsp;&nbsp;<BR>backslash&nbsp;before&nbsp;a&nbsp;non-metacharacter,&nbsp;like&nbsp;regexp&nbsp;{\p},&nbsp;you'll&nbsp;need&nbsp;to&nbsp;&nbsp;<BR>fix&nbsp;it.&nbsp;&nbsp;<BR>&nbsp;<BR>As&nbsp;explained&nbsp;above,&nbsp;the&nbsp;Tcl&nbsp;8.1&nbsp;regular&nbsp;expression&nbsp;engine&nbsp;now&nbsp;interprets&nbsp;<BR>&nbsp;backslash&nbsp;sequences&nbsp;like&nbsp;\n&nbsp;to&nbsp;mean&nbsp;&quot;newline&quot;.&nbsp;It&nbsp;also&nbsp;has&nbsp;four&nbsp;new&nbsp;&nbsp;<BR>kinds&nbsp;of&nbsp;escapes:&nbsp;character&nbsp;entry&nbsp;escapes,&nbsp;class&nbsp;shorthand&nbsp;escapes,&nbsp;&nbsp;<BR>constraint&nbsp;escapes,&nbsp;and&nbsp;back&nbsp;references.&nbsp;Here's&nbsp;an&nbsp;introduction.&nbsp;(The&nbsp;&nbsp;<BR>re_syntax(n)&nbsp;page&nbsp;has&nbsp;full&nbsp;details.)&nbsp;&nbsp;<BR>&nbsp;<BR>A&nbsp;character&nbsp;entry&nbsp;escape&nbsp;is&nbsp;a&nbsp;convenient&nbsp;way&nbsp;to&nbsp;enter&nbsp;a&nbsp;non-printing&nbsp;&nbsp;<BR>or&nbsp;other&nbsp;difficult&nbsp;character.&nbsp;For&nbsp;instance,&nbsp;\n&nbsp;represents&nbsp;a&nbsp;newline&nbsp;&nbsp;<BR>character.&nbsp;\uwxyz&nbsp;(where&nbsp;wxyz&nbsp;is&nbsp;hexadecimal)&nbsp;represents&nbsp;the&nbsp;Unicode&nbsp;&nbsp;<BR>character&nbsp;U+wxyz.&nbsp;&nbsp;<BR>Class&nbsp;shorthand&nbsp;escapes&nbsp;are&nbsp;shorthand&nbsp;for&nbsp;common&nbsp;character&nbsp;classes.&nbsp;&nbsp;<BR>For&nbsp;example,&nbsp;\d&nbsp;stands&nbsp;for&nbsp;[[:digit:]],&nbsp;which&nbsp;means&nbsp;&quot;any&nbsp;single&nbsp;digit.&nbsp;<BR>&quot;&nbsp;&nbsp;<BR>A&nbsp;constraint&nbsp;escape&nbsp;constrains&nbsp;an&nbsp;RE&nbsp;to&nbsp;match&nbsp;only&nbsp;at&nbsp;a&nbsp;certain&nbsp;place.&nbsp;&nbsp;<BR>For&nbsp;example,&nbsp;the&nbsp;constraint&nbsp;escape&nbsp;\m&nbsp;matches&nbsp;only&nbsp;at&nbsp;the&nbsp;start&nbsp;of&nbsp;a&nbsp;&nbsp;<BR>word&nbsp;--&nbsp;so&nbsp;the&nbsp;RE&nbsp;\mhi&nbsp;will&nbsp;match&nbsp;the&nbsp;third&nbsp;word&nbsp;in&nbsp;the&nbsp;string&nbsp;he&nbsp;said&nbsp;&nbsp;<BR>hi&nbsp;but&nbsp;won't&nbsp;match&nbsp;he&nbsp;said&nbsp;thigh.&nbsp;&nbsp;<BR>A&nbsp;back&nbsp;reference&nbsp;matches&nbsp;the&nbsp;same&nbsp;string&nbsp;that&nbsp;was&nbsp;matched&nbsp;by&nbsp;a&nbsp;&nbsp;<BR>previous&nbsp;parenthesized&nbsp;subexpression.&nbsp;(This&nbsp;works&nbsp;like&nbsp;subexpressions&nbsp;in&nbsp;<BR>&nbsp;regsub,&nbsp;but&nbsp;it's&nbsp;used&nbsp;for&nbsp;matching&nbsp;instead&nbsp;of&nbsp;extracting.)&nbsp;For&nbsp;example,&nbsp;<BR>&nbsp;(X.*Y)\1&nbsp;matches&nbsp;any&nbsp;doubled&nbsp;string&nbsp;that&nbsp;starts&nbsp;with&nbsp;X&nbsp;and&nbsp;ends&nbsp;with&nbsp;Y,&nbsp;<BR>&nbsp;such&nbsp;as&nbsp;XYXY,&nbsp;XabcYXabcY,&nbsp;X--YX--Y,&nbsp;etc.&nbsp;&nbsp;<BR>Finally,&nbsp;remember&nbsp;that&nbsp;(as&nbsp;in&nbsp;Tcl&nbsp;8.0&nbsp;and&nbsp;before)&nbsp;some&nbsp;applications,&nbsp;&nbsp;<BR>such&nbsp;as&nbsp;C&nbsp;compilers,&nbsp;interpret&nbsp;these&nbsp;backslash&nbsp;sequences&nbsp;themselves&nbsp;&nbsp;<BR>before&nbsp;the&nbsp;regular&nbsp;expression&nbsp;engine&nbsp;sees&nbsp;them.&nbsp;You&nbsp;may&nbsp;need&nbsp;to&nbsp;double&nbsp;&nbsp;<BR>(or&nbsp;quadruple,&nbsp;etc.)&nbsp;the&nbsp;number&nbsp;of&nbsp;backslashes&nbsp;for&nbsp;these&nbsp;applications.&nbsp;&nbsp;<BR>Still,&nbsp;in&nbsp;straight&nbsp;Tcl&nbsp;8.1&nbsp;code,&nbsp;writing&nbsp;backslash&nbsp;escapes&nbsp;is&nbsp;now&nbsp;both&nbsp;&nbsp;<BR>simpler&nbsp;and&nbsp;more&nbsp;powerful&nbsp;than&nbsp;in&nbsp;8.0&nbsp;and&nbsp;before.&nbsp;&nbsp;<BR>&nbsp;<BR>Bounds&nbsp;<BR>You've&nbsp;seen&nbsp;the&nbsp;quantifiers&nbsp;*,&nbsp;+,&nbsp;and&nbsp;?.&nbsp;They&nbsp;specify&nbsp;&quot;how&nbsp;many&quot;&nbsp;&nbsp;<BR>(respectively,&nbsp;zero&nbsp;or&nbsp;more,&nbsp;one&nbsp;or&nbsp;more,&nbsp;and&nbsp;zero&nbsp;or&nbsp;one).&nbsp;Tcl&nbsp;8.1&nbsp;&nbsp;<BR>added&nbsp;new&nbsp;quantifiers&nbsp;that&nbsp;let&nbsp;you&nbsp;choose&nbsp;exactly&nbsp;how&nbsp;many&nbsp;matches:&nbsp;&nbsp;<BR>the&nbsp;bounds&nbsp;operators,&nbsp;{}.&nbsp;&nbsp;<BR>These&nbsp;operators&nbsp;come&nbsp;in&nbsp;three&nbsp;greedy&nbsp;forms:&nbsp;{m},&nbsp;{m,},&nbsp;and&nbsp;{m,n}.&nbsp;The&nbsp;&nbsp;<BR>corresponding&nbsp;non-greedy&nbsp;forms&nbsp;are&nbsp;{m}?,&nbsp;{m,}?,&nbsp;and&nbsp;{m,n}?.&nbsp;&nbsp;<BR>&nbsp;<BR>The&nbsp;{m}&nbsp;quantifier&nbsp;matches&nbsp;exactly&nbsp;m&nbsp;occurrences.&nbsp;So&nbsp;does&nbsp;{m}?.&nbsp;For&nbsp;&nbsp;<BR>example,&nbsp;either&nbsp;#{70}&nbsp;or&nbsp;#{70}?&nbsp;match&nbsp;a&nbsp;string&nbsp;of&nbsp;exactly&nbsp;70&nbsp;#&nbsp;&nbsp;<BR>characters.&nbsp;&nbsp;<BR>The&nbsp;{m,}&nbsp;quantifier&nbsp;matches&nbsp;at&nbsp;least&nbsp;m&nbsp;occurrences.&nbsp;Here's&nbsp;a&nbsp;demo&nbsp;of&nbsp;the&nbsp;<BR>&nbsp;greedy&nbsp;and&nbsp;non-greedy&nbsp;versions:&nbsp;&nbsp;<BR>&nbsp;<BR>%&nbsp;set&nbsp;x&nbsp;{a##b#######c}&nbsp;<BR>a##b#######c&nbsp;<BR>%&nbsp;regexp&nbsp;{#{4,}}&nbsp;$x&nbsp;match;&nbsp;set&nbsp;match&nbsp;<BR>#######&nbsp;<BR>%&nbsp;regexp&nbsp;{#{4,}?}&nbsp;$x&nbsp;match;&nbsp;set&nbsp;match&nbsp;<BR>####&nbsp;<BR>&nbsp;<BR>Notice&nbsp;that&nbsp;the&nbsp;first&nbsp;two&nbsp;number&nbsp;signs&nbsp;(##)&nbsp;in&nbsp;the&nbsp;string&nbsp;are&nbsp;never&nbsp;&nbsp;<BR>matched&nbsp;because&nbsp;there&nbsp;aren't&nbsp;at&nbsp;least&nbsp;four&nbsp;of&nbsp;them.&nbsp;&nbsp;<BR>The&nbsp;{m,n}&nbsp;quantifier&nbsp;matches&nbsp;at&nbsp;least&nbsp;m&nbsp;but&nbsp;no&nbsp;more&nbsp;than&nbsp;n&nbsp;occurrences.&nbsp;<BR>&nbsp;&nbsp;<BR>For&nbsp;example,&nbsp;the&nbsp;RE&nbsp;<A HREF="http://([^/]+/?){1,3}">http://([^/]+/?){1,3}</A>&nbsp;would&nbsp;match&nbsp;Web&nbsp;URLs&nbsp;that&nbsp;have&nbsp;<BR>&nbsp;3&nbsp;components&nbsp;(like&nbsp;<A HREF="http://xyz.fr/euro/billets.htm),">http://xyz.fr/euro/billets.htm),</A>&nbsp;or&nbsp;with&nbsp;2&nbsp;&nbsp;<BR>components&nbsp;(like&nbsp;<A HREF="http://xyz.fr/euro/,">http://xyz.fr/euro/,</A>&nbsp;or&nbsp;with&nbsp;just&nbsp;1&nbsp;component&nbsp;(like&nbsp;&nbsp;<BR><A HREF="http://xyz.fr).">http://xyz.fr).</A>&nbsp;The&nbsp;RE&nbsp;matches&nbsp;a&nbsp;final&nbsp;slash&nbsp;(/)&nbsp;if&nbsp;there&nbsp;is&nbsp;one.&nbsp;As&nbsp;&nbsp;<BR>always,&nbsp;a&nbsp;greedy&nbsp;match&nbsp;will&nbsp;match&nbsp;as&nbsp;long&nbsp;a&nbsp;string&nbsp;as&nbsp;possible:&nbsp;it&nbsp;would&nbsp;<BR>&nbsp;try&nbsp;for&nbsp;3&nbsp;matches.&nbsp;&nbsp;<BR>&nbsp;<BR>A&nbsp;non-greedy&nbsp;quantifier&nbsp;would&nbsp;try&nbsp;to&nbsp;match&nbsp;the&nbsp;least&nbsp;(1&nbsp;match).&nbsp;But&nbsp;be&nbsp;&nbsp;<BR>careful:&nbsp;<A HREF="http://([^/]+/?){1,3}?">http://([^/]+/?){1,3}?</A>&nbsp;won't&nbsp;match&nbsp;all&nbsp;the&nbsp;way&nbsp;to&nbsp;a&nbsp;possible&nbsp;&nbsp;<BR>slash&nbsp;because&nbsp;it&nbsp;matches&nbsp;the&nbsp;fewest&nbsp;characters&nbsp;possible!&nbsp;(With&nbsp;input&nbsp;&nbsp;<BR><A HREF="http://xyz.fr/,">http://xyz.fr/,</A>&nbsp;that&nbsp;RE&nbsp;would&nbsp;match&nbsp;just&nbsp;<A HREF="http://x.)">http://x.)</A>&nbsp;This&nbsp;brings&nbsp;up&nbsp;one&nbsp;&nbsp;<BR>of&nbsp;the&nbsp;many&nbsp;subtleties&nbsp;in&nbsp;these&nbsp;advanced&nbsp;regular&nbsp;expressions:&nbsp;that&nbsp;the&nbsp;&nbsp;<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -