정규 표현 식 간단하게 정리 (전자 우편 예시)
,
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">
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.