Regular expression, practice

xiaoxiao2021-03-06  36

These two days, start learning regular expressions and start practicing.

First, I didn't download the procedure for the regular expression tester, because I used a web tester, its code comes from:

Regular expression practice http://www.codefans.com/ArticleView /Article_5600.html

Open the page above, copy the HTML code, and save it as an HTM file.

If you don't want to watch the page above, I will put me the page code that I get in the above steps below:

Regular expression Exerciseer </ title> <meta name = Anhui Chizhou Statistics Bureau Xu Zuling E-mail: czjsz@stats.gov.cn> <script language = "javascript"> Function OnMove ) {WINDOW.STATUS = "(" Window.Event.ClientX ")" "::" Document.Location} </ script> <script language = "javascript1.2" > var RE = new regexp () // Establish regular expression object VAR nextPoint = 0 // Off Offset // Set Regular Expression Function SetPattern (Form) {var Modeif (form.chkmode.checked) Mode = "gi" // i: No case in case G: Global, seems to have no effect else mode = "g" Re.Compile (form.regexp.value, mode) NextPoint = 0Form.Reglist.Value = "} // Check if there is a match function Findit (Form) {setPattern (Form) var input = form.main.valueif (INPUT.SEARCH (RE)! = -1) {form.output [0] .CHECKED = true} else {form. Output [1] .checked = true}} // Check matching position function locateit (form) {setpattern (form) var input = form.main.valueform.offset.Value = Input.search (re)} // Check all Match Function Execit (Form) {var Modeif (form.chkmode.checked) mode = "gi" else mode = "g" var regexparray = form.regexp.Value.Split ("/ r / n") // Get regular Expression to array if (NextPoint == 0) Form.Reglist .value = "" var key = true.checked "key = false nextpoint = 0do {var offs = 9999999999var POS = -1Var input = form.main.value.substr (nextpoint) // Volume to each regular expression Match for (VAR i = 0; i <regexparray.length; i ) {re.Compile (regexparray [i], mode) var matcharray = RE.EXEC (INPUT) IF (matcharray) {if (Offs> matcharray. Index) {OFFS = Matcharray.indexpos = I // Save the nearest match of the starting position}}} f (pOS> =</p> <p>0) {RE.Compile (regexparray [POS], Mode) Var Matcharray = Re.exec (Input) for (var i = 1; i <matcharray.length; i ) matcharray [i] = " i ": " matcharray [i] form.reglist.value =" [" (POS 1) "] (NextPoint Matcharray.index) "=>" Matcharray [0] "/ n" Form .reglist.valueform.matchlist.value = "$ 0:" matcharray.join ("/ n") NextPoint = NextPoint matcharray.index matcharray [0] .length} else {if (! key) form.reglist.Value = "Nothing to find / n" form.reglist.value form.matchlist.value = "" NextPoint = 0key = false}} while (key)} // Set the current regular expression function setRegexp (n) {var s = Document.all.RegexPlist.Value.split ("/ r / n") Document.all.Regexp.Value = s [n * 2-1] //.replace ("/r" ,"")nextpoint = 0 } // Define Select Monitor VAR ISNAV = (Navigator.Appname == "Netscape") Function ShowSelection () {if (isnav) {var thetext = Document.getSelection ()} else {var}} else {var}} else {var ttext = .Text} if (Thet.Length> 0 && document.all.Selechkmode.Checked) Document.all.Regexp.Value = THET} if (isnav) {document.captureevents (event.mouseup)} Document.onm OUSEUP = ShowSelection </ script> </ head> <body style = "font-size = 9pt;" onmousemove = onmove ()> <form> <Table Width = 100% cellspacing = 0 cellpadding = 0> <TR> <TD > <font color = red> regular expression Exercise </ font> </ td> <td align = right> <a href=mailto: CZJSZ_AH@stats.gov.cn czjsz_ah@stats.gov.cn </ a > </ td> </ tr> </ table> <Table Width = 100% Broder =</p> <p>1 frame = Above rules = none style = "font-size: 9pt;"> <tr> <td width = 50% valign = TOP> Enter some text: <br> <textarea name = "main" cols = 58 rows = 5 Wrap = "Virtual" style = "font-size: 9pt;"> 09-11-2001 09/11/2001 czjsz_ah@stats.gov.cnasdff 12345 196.168.1.3 www.sohu.com ftp: // Www.chinaasp.com 2001.9.11 http://www.active.com.cn/club/bbs/bbsview.asp http://www.163.com/inden.htm </ textarea> <br> Matching Regular expression: ignore the case <input type = "checkbox" name = "chkmode" checked style = "font-size: 8pt; height: 18px"> <br> <textarea name = "regexp" cols = 51 rows = 5 Style = "font-size: 9pt;"> </ textarea> <input type = "" value = "clear" onclick = "this.form.Regexp.value = ''" style = "font-size: 8pt; Height: 18px "> <br> <input type =" Button "value =" Can you find? [RegexObject.test (String)] "style =" font-size: 8pt; width: 70%; Height: 18px "Onclick = "Findit (this.form)> <input type =" Radio "name =" Output "style =" font-size: 8pt; height: 18px "> YES <input type =" radio "name =" Output "style = "font-size: 8pt; height: 18px"> no <br> <input type = "Button" value = "Where? [String.Search]" Style = "fo NT-size: 8pt; width: 70%; Height: 18px "onclick =" Locateit (this.form)> <input type = "name =" OFFSET "size = 4 style =" font-size: 8pt; Height: 18px "> </ td> <TD Valign = TOP> Test Regular Expression List: Using the No. INPUT TYPE = Text Name =</p> <p>Num size = 2 value = 1 style = "font-size: 8pt; height: 18px" >> <input type = button value = Go onclick = setRegeXP (this.form.num.value) style = "font-size: 8pt Height: 18px "> Allow copy <input type =" checkbox "name =" selechkmode "style =" font-size: 8pt; height: 18px "> <textarea name =" regexplist "cols = 58 rows = 14 wrap = Off Style = "font-size: 9pt;"> 1. Check the date: (1 [0-2] | 0? [1-9]) [-. /] (0? [1-9] | [12] [ 0-9] | 3 [01]) [-. /] (/ D / D / D / D)) 2. Check the number: ([- ]? [0-9] /.? [0-9 ] ) 3. Check the URL: ((http | ftp): //)? ((((((((([/ D] /.) ) {3} [/ d] (/ [/W./] )?) ([AZ] / w * ((/. [w ) ) {2,}) ([/] [/ w. ~] *) *) 4. Check E-mail / w @ ((( / W [.]?) ))</TEXTAREA> </t> </TEXTAREA = Bottom> <input type = "Button" value = "? [RegexObject.exec (String) ] "style =" font-size: 8pt; width: 70%; Height: 18px "onclick =" EXECIT (this.form)> Single-step <input type = "checkbox" name = "scankmode" style = "font- Size: 8pt; Height: 18px "> <weight" color "cols = 58 rows = 8 style =" font-size: 9pt; "> </ textarea> </ td> <td valign = bottom> Matching ingredients: (visible when walking) <textarea name = "matchlist" cols = 58 rows = 8 style = "font-size: 9pt;"> </ textarea> </ td> </ tr> </ table > </ Form> <script> setRegexp (1) </ script> </ body> </ html> then open this web page, start learning and exercise testing. The code I tested is: Use Baidu to find keywords: The page source file obtained after the regular expression. I wrote the following test expressions based on my purpose. Test numbers.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-64279.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="64279" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.041</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '7wVVIFob7vzthTb07mWIdrau6uUTMpPvn9n5RNo0jDODDvOMywx6T0deDtthVcHHKtAxMNw84nOkqFP_2FeuOvIw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>