사용자 도구

사이트 도구


wiki:javascript:javascript_note:js_regexp

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
wiki:javascript:javascript_note:js_regexp [2021/04/22 16:57]
emblim98 [Example of Quantifiers ( n? )]
wiki:javascript:javascript_note:js_regexp [2023/01/13 18:44] (현재)
줄 342: 줄 342:
  
 =====Using the RegExp Object===== =====Using the RegExp Object=====
 +%%JavaScript%%에서 %%RegExp%% 오브젝트는 미리 정의된 속성 및 메서드가 있는 정규식 오브젝트입니다.\\
  
 +=====Using test()=====
 +''test()'' 메서드는 %%RegExp%%(정규식) 메서드입니다.\\
 +\\
 +문자열에서 패턴을 검색하고, 결과에 따라 %%true%% 또는 %%false%%를 반환합니다.\\
 +\\
 +다음 예제는 문자열에서 %%"e"%% 문자를 검색합니다.\\
  
 +====Example====
 +<code javascript>
 +var patt = /e/;
 +patt.test("The best things in life are free!");
 +</code>
 +\\
 +문자열에 %%"e"%%가 있으므로, 상기 코드의 출력값은 %%true%%입니다.\\
 +\\
 +먼저 정규식을 변수에 넣을 필요가 없습니다. 위의 두 줄을 아래와 같이 한 줄로 줄일 수 있습니다.\\
 +\\
 +<code javascript>
 +/e/.test("The best things in life are free!");
 +</code>
 +\\
 +<code javascript>
 +<!DOCTYPE html>
 +<html>
 +<body>
 +  <h2>JavaScript Regular Expressions</h2>
 +  <p>Search for an "e" in the next paragraph:</p>
 +  <p id="p01">The best things in life are free!</p>
 +  <p id="demo"></p>
 +  <script>
 +    text = document.getElementById("p01").innerHTML;
 +    document.getElementById("demo").innerHTML = /e/.test(text);
 +  </script>
 +</body>
 +</html>
 +</code>
 +\\
 +=====Using exec()=====
 +''exec()'' 메서드는 %%RegExp%% 정규식 메서드입니다.\\
 +\\
 +문자열에서 지정된 패턴을 검색하고, 찾은 텍스트를 오브젝트로 반환합니다.\\
 +\\
 +일치하는 항목이 없으면, 빈 %%(null)%% 개체를 반환합니다.\\
 +\\
 +다음 예제는 문자열에서 "e" 문자를 검색합니다.\\
  
 +====Example====
 +<code javascript>
 +  <script>
 +    let obj = /e/.exec("The best things in life are free!");
 +    document.getElementById("demo").innerHTML = "Found " + obj[0] + " in position " + obj.index + " in the text: " + obj.input;
 +    /* Found e in position 2 in the text: The best things in life are free! */
 +  </script>
 +</code>
  
- +=====Complete RegExp Reference===== 
 +전체 참조를 보려면 [[https://www.w3schools.com/jsref/jsref_obj_regexp.asp|Complete JavaScript RegExp Reference]]로 이동하십시오.\\ 
 +\\ 
 +모든 %%RegExp%% 속성 및 메서드에 대한 설명과 예제가 포함되어 있습니다.\\
  
  
  
 {{tag>오션 Javascript Regular Expressions}}  {{tag>오션 Javascript Regular Expressions}}
/volume1/web/dokuwiki/data/attic/wiki/javascript/javascript_note/js_regexp.1619078268.txt.gz · 마지막으로 수정됨: 2022/03/10 19:52 (바깥 편집)