정규 표현 식 간단하게 정리 (전자 우편 예시)

9940 단어



	export default</span> <span class="token punctuation">{</span>
		<span class="token selector">data()</span> <span class="token punctuation">{</span>
			<span class="token selector">return</span> <span class="token punctuation">{</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token selector">,
		onLoad()</span> <span class="token punctuation">{</span>
			// this.<span class="token function">meansOne</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			// this.<span class="token function">meanstWO</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			this.<span class="token function">meansThree</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token selector">,
		methods:</span> <span class="token punctuation">{</span>
			<span class="token selector">//    
			meansOne: function()</span> <span class="token punctuation">{</span>
				<span class="token comment">/*
				 *                 aaa 
				 *                 ,            
				 * {n}    n 
				 * {n,m}  n-m 
				 * {n,}  n   
				 * +    
				 * *0   
				 * ?0   
				 * ^n      n  
				 * ^     
				 * $    
				 */</span>
				<span class="token selector">// var reg = /(ab)</span><span class="token punctuation">{</span>2<span class="token punctuation">}</span><span class="token selector">/
				// var reg = /b</span><span class="token punctuation">{</span>3<span class="token punctuation">}</span><span class="token selector">/
				//     abc,abbc,abbbc
				var reg = /ab+c/
				var str = "acdasdaaabbcb"
				// console.log(reg.test(str))
				//     132  
				//^132
				// var reg = /^(132)/
				var reg = /(132)$/
				var phone = "13221366666132"
				console.log(reg.test(phone))
				//       11  、   1、   3-9    、
				var reg = /^1[3-9][0-9]</span><span class="token punctuation">{</span>9<span class="token punctuation">}</span>$/

			<span class="token punctuation">}</span><span class="token selector">,
			//    
			meanstWO: function()</span> <span class="token punctuation">{</span>
				<span class="token comment">/*
				 *             .
				 * .      
				 *        \     
				 * \.  .
				 * \\    \
				 *          ,          , \          
				 *   \  \\   
				 */</span>
				var reg = /\./
				var str = <span class="token string">"bbb."</span>
				// console.<span class="token function">log</span><span class="token punctuation">(</span>reg.<span class="token function">test</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">)</span>
				var reg = new <span class="token function">RegExp</span><span class="token punctuation">(</span><span class="token string">"\\."</span><span class="token punctuation">)</span>
				var str = <span class="token string">"bbb."</span>
				// console.<span class="token function">log</span><span class="token punctuation">(</span>reg.<span class="token function">test</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">)</span>
				<span class="token comment">/*
				 * \w -    、  、     [A-z0-9_]
				 * \W -     、  、   
				 * \d -     
				 * \D -       [^0-9]
				 * \s -   
				 * \S -     
				 * \b -     
				 * \B -       
				 */</span>
				var reg = /\d/
				var str = <span class="token string">"123123123"</span>
				// console.<span class="token function">log</span><span class="token punctuation">(</span>reg.<span class="token function">test</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">)</span>

				//                     hello  
				var reg = /\bhello\b/
				var str = <span class="token string">"heloo hello oo"</span>
				// console.<span class="token function">log</span><span class="token punctuation">(</span>reg.<span class="token function">test</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">)</span>
				//    
				var str = <span class="token string">"      asdasd"</span>
				// var arr =  str.<span class="token function">replace</span><span class="token punctuation">(</span>/^\s/,<span class="token string">""</span><span class="token punctuation">)</span>
				//     
				// var arr =  str.<span class="token function">replace</span><span class="token punctuation">(</span>/^\s*/,<span class="token string">""</span><span class="token punctuation">)</span>
				//     
				var arr =  str.<span class="token function">replace</span><span class="token punctuation">(</span>/\s*$/,<span class="token string">""</span><span class="token punctuation">)</span>
				//          /^\s*|\s*$/<span class="token property">g</span><span class="token punctuation">:</span>        
				var arr =  str.<span class="token function">replace</span><span class="token punctuation">(</span>/^\s*|\s*$/g,<span class="token string">""</span><span class="token punctuation">)</span>
				console.<span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span>
				
			<span class="token punctuation">}</span><span class="token selector">,
			//   :    
			meansThree: function()</span> <span class="token punctuation">{</span>
				<span class="token comment">/*
				*       :******@
				* -           
				* -\w{3,} (\.\w+)* @ [A-z0-9]+ (\.[A-z]{2,5}){1,2}
				*/</span> 
			 <span class="token selector">var emailReg = /^\w</span><span class="token punctuation">{</span>3,<span class="token punctuation">}</span><span class="token selector">(\.\w+)*@[A-z0-9]+(\.[A-z]</span><span class="token punctuation">{</span>2,5<span class="token punctuation">}</span><span class="token selector">)</span><span class="token punctuation">{</span>1,2<span class="token punctuation">}</span>$/
			 var email = <span class="token function">prompt</span><span class="token punctuation">(</span><span class="token string">"       "</span><span class="token punctuation">)</span>
			 console.<span class="token function">log</span><span class="token punctuation">(</span>emailReg.<span class="token function">test</span><span class="token punctuation">(</span>email<span class="token punctuation">)</span><span class="token punctuation">)</span>


			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>
<span class="token selector">



좋은 웹페이지 즐겨찾기