IT정리노트

블로그 이미지

Edward. K

메멘토적 기억능력을 소유한 개발자 노트.

자바스크립트 정규식 사용 예제

Programming/JavaScript 2009. 3. 25. 13:29


Link :  http://www.javascriptkit.com/javatutors/redev3.shtml

아이디 생성시 제한 아이디를 설정해주기 위해.....

<script language="JavaScript">
<!--
 function checkId(str) {
  str = str.toLowerCase();
  var len =str.length;
  var noId =['root','admin','webmater','mail','jboss','oracle','mysql','localhost','user'];
  for( var i=0; i<noId.length ; i++) {
   //str = str.replace(eval('/(['+noId[i]+'])/') ,'');
   str = str.replace(eval('/'+noId[i]+'/') ,'');
  }
  // 삭제된 결과가 기존 길이보다 작을 경우는
  //   입력 금지 아이디와 동일하다고 판단
  if( str.length < len ){
   alert('---: '+str);  
  }
 } 
 checkId ("rootff123");
 checkId ("aduser23");
//-->
</script>


 

Regular Expressions methods and usage

Now, knowing how a RegExp is written is only half the game. To gain anything from them you have to know how to use them too. There are a number of ways to implement a RegExp, some through methods belonging to the String object, some through methods belonging to the RegExp object. Whether the regular expression is declared through an object constructor or a literal makes no difference as to the usage.

Description Example
RegExp.exec(string)
Applies the RegExp to the given string, and returns the match information. var match = /s(amp)le/i.exec("Sample text")

match then contains ["Sample","amp"]
RegExp.test(string)
Tests if the given string matches the Regexp, and returns true if matching, false if not. var match = /sample/.test("Sample text")

match then contains false
String.match(pattern)
Matches given string with the RegExp. With g flag returns an array containing the matches, without g flag returns just the first match or if no match is found returns null. var str = "Watch out for the rock!".match(/r?or?/g)

str then contains ["o","or","ro"]
String.search(pattern)
Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not. var ndx = "Watch out for the rock!".search(/for/)

ndx then contains 10
String.replace(pattern,string)
Replaces matches with the given string, and returns the edited string. var str = "Liorean said: My name is Liorean!".replace(/Liorean/g,'Big Fat Dork')

str then contains "Big Fat Dork said: My name is Big Fat Dork!"
String.split(pattern)
Cuts a string into an array, making cuts at matches. var str = "I am confused".split(/\s/g)

str then contains ["I","am","confused"]

On that note I conclude the tutorial. Now go express yourself with JavaScript regular expressions!

  • Tutorial introduction
  • Regular Expression patterns
  • Regular Expression methods and usage

This tutorial is written by David Andersson (Liorean). Liorean is a twenty years old medical student and hobbyist web designer mostly working with JavaScript and CSS, DOM and the newest html standards available.

저작자표시비영리변경금지
  • 카카오스토리
  • 트위터
  • 페이스북
Posted by Edward. K

트랙백

※ 스팸 트랙백 차단중 ...{ ? }
이전페이지 다음페이지
블로그 이미지

메멘토적 기억능력을 소유한 개발자 노트.

by Edward. K

공지사항

    최근...

  • 포스트
  • 댓글
  • 트랙백
  • linux ls 날자 형식 변경 + 파일⋯
  • linux 설치된 APACHE HTTPD, TOMCA⋯
  • 통신(포트) 상태 확인 > ping, tel⋯
  • Referenced file contains errors⋯
  • 이클립스에서 SVN 연결 해제.
  • 더 보기
  • 알고나니까 너무 웃기네요 ㅋㅋ 감⋯
    석유고갈 ㆍ 04.14
  • 감사합니다 ㄷㄷ
    ㅇㅇ ㆍ 04.06
  • rtrtㄳㄳㄳ
    ㄱㄳ ㆍ 03.11
  • rtrtㄳㄳㄳ
    ㄱㄳ ㆍ 03.11
  • 이유는 없고 그냥 이렇게하니까 되⋯
    ㅇㅇ ㆍ 03.08

태그

  • tomcat
  • Jboss
  • EkNote
  • iBATIS
  • 전자정부프레임워크
  • toad
  • STS
  • 이클립스
  • Eclipse
  • 색상코드표
  • 이미지 편집
  • 컴퓨터 관리
  • 개한민국
  • sqlgate
  • EditPlus
  • android
  • 중독성게임
  • rocketdock
  • Graphic
  • flex
  • eclipse plugin
  • netbeans
  • 캡쳐툴
  • ERwin
  • 가상화폐무료
  • egov
  • 미네르바
  • 사업 이야기
  • 플래시 게임
  • Flash Player

글 보관함


  • 2021/12
    (3)

  • 2021/11
    (7)

  • 2021/09
    (1)
«   2022/07   »
일 월 화 수 목 금 토
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

링크

카테고리

분류 전체보기 (778)
행운이와함께 (1)
EkNote Project (18)
ARIS (0)
Android (2)
LINK (37)
UML (9)
Programming (152)
Cobol (0)
ASP (0)
CSS (5)
C_C++ (2)
IBatis (2)
JSP (3)
JAVA (76)
JavaScript (44)
PHP (0)
Utility (76)
Protable (3)
MobileProgram (4)
SKT (0)
KTF (0)
LGT (0)
자료들 (4)
DB (81)
mongoDB (0)
MySQL (8)
Oracle (60)
MSSQL (4)
Graphic (8)
Flash (3)
PhotoShop (3)
SourceFactory (4)
Collection (67)
작가의기막힌상상력 (13)
미소를찾아보는공간 (42)
내심장은작동중일까 (6)
멀더와스컬리의노트 (1)
이건어디에사용할까 (5)
Edward (274)
나만 알기엔 아까워 (100)
기억하기 위한 기록 (122)
시선이 머무는 공간 (50)
숨기고 싶은 이야기 (2)

카운터

Total
1,377,425
Today
221
Yesterday
197
방명록 : 관리자 : 글쓰기
Edward. K's Blog is powered by daumkakao
Skin info material T Mark3 by 뭐하라
favicon

IT정리노트

메멘토적 기억능력을 소유한 개발자 노트.

  • 태그
  • 링크 추가
  • 방명록

관리자 메뉴

  • 관리자 모드
  • 글쓰기
  • 분류 전체보기 (778)
    • 행운이와함께 (1)
    • EkNote Project (18)
    • ARIS (0)
    • Android (2)
    • LINK (37)
    • UML (9)
    • Programming (152)
      • Cobol (0)
      • ASP (0)
      • CSS (5)
      • C_C++ (2)
      • IBatis (2)
      • JSP (3)
      • JAVA (76)
      • JavaScript (44)
      • PHP (0)
    • Utility (76)
      • Protable (3)
    • MobileProgram (4)
      • SKT (0)
      • KTF (0)
      • LGT (0)
      • 자료들 (4)
    • DB (81)
      • mongoDB (0)
      • MySQL (8)
      • Oracle (60)
      • MSSQL (4)
    • Graphic (8)
      • Flash (3)
      • PhotoShop (3)
    • SourceFactory (4)
    • Collection (67)
      • 작가의기막힌상상력 (13)
      • 미소를찾아보는공간 (42)
      • 내심장은작동중일까 (6)
      • 멀더와스컬리의노트 (1)
      • 이건어디에사용할까 (5)
    • Edward (274)
      • 나만 알기엔 아까워 (100)
      • 기억하기 위한 기록 (122)
      • 시선이 머무는 공간 (50)
      • 숨기고 싶은 이야기 (2)

카테고리

PC화면 보기 티스토리 Daum

티스토리툴바