{"id":582,"date":"2011-12-14T11:17:46","date_gmt":"2011-12-14T03:17:46","guid":{"rendered":"http:\/\/www.clonefactor.com\/wordpress\/?p=582"},"modified":"2013-08-17T23:17:01","modified_gmt":"2013-08-17T15:17:01","slug":"regexp","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/webdevelop\/582\/","title":{"rendered":"RegExp"},"content":{"rendered":"<p>RegExp ! you know what is RegExp ??<\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td><span style=\"font-size: medium; color: #808080;\"><em>it&#8217;s a piece of shit!!!<\/em><\/span><br \/>\n<span style=\"font-size: medium; color: #808080;\"><em>But we need it. Are we?<\/em><\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right;\">&#8211; Canis<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img decoding=\"async\" title=\"{#th_012_a.gif}\" src=\"http:\/\/www.clonefactor.com\/wordpress\/wp-content\/plugins\/tinymce-advanced\/mce\/emotions\/img\/onion\/bigimage\/th_012_a.gif\" alt=\"{#th_012_a.gif}\" border=\"0\" \/><img decoding=\"async\" title=\"{#th_012_b.gif}\" src=\"http:\/\/www.clonefactor.com\/wordpress\/wp-content\/plugins\/tinymce-advanced\/mce\/emotions\/img\/onion\/bigimage\/th_012_b.gif\" alt=\"{#th_012_b.gif}\" border=\"0\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>RegExp\u00a0\u6578\u5b57\u985e\u578b<\/p>\n<p>[js]\/\/select integers only<br \/>\nvar intRegex = \/[0-9 -()+]+$\/;<br \/>\n\/\/match any ip address<br \/>\nvar ipRegex = &#8216;bd{1,3}.d{1,3}.d{1,3}.d{1,3}b&#8217;;<br \/>\n\/\/match number in range 0-255<br \/>\nvar num0to255Regex = &#8216;^([01][0-9][0-9]|2[0-4][0-9]|25[0-5])$&#8217;;<br \/>\n\/\/match number in range 0-999<br \/>\nvar num0to999Regex = &#8216;^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$&#8217;;<br \/>\n\/\/match ints and floats\/decimals<br \/>\nvar floatRegex = &#8216;[-+]?([0-9]*.[0-9]+|[0-9]+)&#8217;;<br \/>\n\/\/Match Any number from 1 to 50 inclusive<br \/>\nvar number1to50Regex = \/(^[1-9]{1}$|^[1-4]{1}[0-9]{1}$|^50$)\/gm;[\/js]<\/p>\n<p>RegExp \u8a8d\u8b49\u985e\u578b<\/p>\n<p>[js]\/\/match email address<br \/>\nvar emailRegex = &#8216;^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$&#8217;;<br \/>\n\/\/match credit card numbers<br \/>\nvar creditCardRegex = &#8216;^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35d{3})d{11})$&#8217;;<br \/>\n\/\/match username<br \/>\nvar usernameRegex = &#8216;\/^[a-z0-9_-]{3,16}$\/&#8217;;<br \/>\n\/\/match password<br \/>\nvar passwordRegex = &#8216;\/^[a-z0-9_-]{6,18}$\/&#8217;;<br \/>\n\/\/Match 8 to 15 character string with at least one upper case letter, one lower case letter, and one digit (useful for passwords).<br \/>\nvar passwordStrengthRegex = \/((?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,15})\/gm;<br \/>\n\/\/match elements that could contain a phone number<br \/>\nvar phoneNumber = \/[0-9-()+]{3,20}\/;[\/js]<\/p>\n<p>RegExp \u65e5\u671f\u985e\u578b<\/p>\n<p>[js]<br \/>\n\/\/MatchDate (e.g. 21\/3\/2006)<br \/>\nvar dateRegex = \/(d{1,2}\/d{1,2}\/d{4})\/gm;<br \/>\n\/\/match date in format MM\/DD\/YYYY<br \/>\nvar dateMMDDYYYRegex = &#8216;^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)dd$&#8217;;<br \/>\n\/\/match date in format DD\/MM\/YYYY<br \/>\nvar dateDDMMYYYRegex = &#8216;^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)dd$&#8217;;<br \/>\n[\/js]<\/p>\n<p>RegExp URL \u985e\u578b<\/p>\n<p>[js]<br \/>\n\/\/match a url<br \/>\nvar urlRegex = &#8216;\/^(https?:\/\/)?([da-z.-]+).([a-z.]{2,6})([\/w .-]*)*\/?$\/&#8217;;<br \/>\n\/\/match a url slug (letters\/numbers\/hypens)<br \/>\nvar urlslugRegex = &#8216;\/^[a-z0-9-]+$\/&#8217;;[\/js]<\/p>\n<p>RegExp \u767c\u97f3\u5b57<\/p>\n<p>[js]<br \/>\n\/\/select vowels only<br \/>\nvar vowelRegex = \/^[aeiou]\/;[\/js]<\/p>\n<p>RegExp \u7279\u6b8a\u5b57\u5143<\/p>\n<p>[js]<br \/>\n\/\/select whitespace<br \/>\nvar whiteSpaceRegex = &#8216;^[ t]+&#8217;;<br \/>\n\/\/select whitespace and tabs<br \/>\nvar whiteSpaceRegex = &#8216;^[ t]+|[ t]+$&#8217;;<br \/>\n\/\/select whitespace and linebreaks<br \/>\nvar whiteSpaceRegex = &#8216;[ trn]&#8217;;<br \/>\n\/\/replace newline characters with &lt;br \/&gt; tags<br \/>\nnewLineToBr = function(str) { return str.replace(\/(rn|[rn])\/g, &#8216;&lt;br \/&gt;&#8217;); }[\/js]<\/p>\n<p>RegExp \u7db2\u5740\u985e\u578b<\/p>\n<p>[js]<br \/>\n\/\/match domain name (with HTTP)<br \/>\nvar domainRegex = \/(.*?)[^w{3}.]([a-zA-Z0-9]([a-zA-Z0-9-]{0,65}[a-zA-Z0-9])?.)+[a-zA-Z]{2,6}\/igm;<br \/>\n\/\/match domain name (www. only)<br \/>\nvar domainRegex = \/[^w{3}.]([a-zA-Z0-9]([a-zA-Z0-9-]{0,65}[a-zA-Z0-9])?.)+[a-zA-Z]{2,6}\/igm;<br \/>\n\/\/match domain name (alternative)<br \/>\nvar domainRegex = \/(.*?).(com|net|org|info|coop|int|com.au|co.uk|org.uk|ac.uk|)\/igm;<br \/>\n\/\/match sub domains: www, dev, int, stage, int.travel, stage.travel<br \/>\nvar subDomainRegex = \/(http:\/\/|https:\/\/)?(www.|dev.)?(int.|stage.)?(travel.)?(.*)+?\/igm;<br \/>\n[\/js]<\/p>\n<p>RegExp \u5716\u7247\u985e\u578b<\/p>\n<p>[js]<br \/>\n\/\/Match jpg, gif or png image<br \/>\nvar imageRegex = \/([^s]+(?=.(jpg|gif|png)).2)\/gm;<br \/>\n\/\/match all images<br \/>\nvar imgTagsRegex = \/&lt;img.+?src=&quot;(.*?)&quot;.+?&gt;\/ig;<br \/>\n\/\/match just .png images<br \/>\n&lt;img.+?src=&quot;(.*?.png)&quot;.+?&gt;[\/js]<\/p>\n<p>RegExp \u5176\u4ed6\u6709\u7528\u7684<\/p>\n<p>[js]<br \/>\n\/\/match RGB (color) string<br \/>\nvar rgbRegex = \/^rgb((d+),s*(d+),s*(d+))$\/;<br \/>\n\/\/match hex (color) string<br \/>\nvar hexRegex = &#8216;\/^#?([a-f0-9]{6}|[a-f0-9]{3})$\/&#8217;;<br \/>\n\/\/Match Valid hexadecimal colour code<br \/>\nvar hexRegex = \/(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)\/gm;<br \/>\n\/\/match a HTML tag (v1)<br \/>\nvar htmlTagRegex = &#8216;\/^&lt;([a-z]+)([^&lt;]+)*(?:&gt;(.*)&lt;\/1&gt;|s+\/&gt;)$\/&#8217;;<br \/>\n\/\/match HTML Tags (v2)<br \/>\nvar htmlTagRegex = \/(&lt;(\/?[^&gt;]+)&gt;)\/gm;<br \/>\n\/\/match \/product\/123456789<br \/>\nvar productUrlRegex = &#8216;(\/product\/)?+[0-9]+&#8217;;<br \/>\n\/\/Match Letters, numbers and hyphens<br \/>\nvar lnhRegex = \/([A-Za-z0-9-]+)\/gm;<br \/>\n\/\/match all .js includes<br \/>\nvar jsTagsRegex = \/&lt;script.+?src=&quot;(.+?.js(?:?v=d)*).+?script&gt;\/ig;<br \/>\n\/\/match all .css includes<br \/>\nvar cssTagsRegex = \/&lt;link.+?href=&quot;(.+?.css(?:?v=d)*).+?&gt;\/ig;[\/js]<\/p>\n<p>\u5f15\u7528\u81ea : <a href=\"http:\/\/www.jquery4u.com\/syntax\/jquery-basic-regex-selector-examples\/\">http:\/\/www.jquery4u.com\/syntax\/jquery-basic-regex-selector-examples\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>RegExp ! you know what is RegExp ?? it&#8217;s a p &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[27,38],"class_list":["post-582","post","type-post","status-publish","format-standard","hentry","category-webdevelop","tag-javascript","tag-regex"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=582"}],"version-history":[{"count":0,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/582\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}