메뉴 건너뛰기

Dev tips

Regular Expressions Cheat Sheet by 

A quick reference guide for regular expressions (regex), including symbols, ranges, grouping, assertions and some sample patterns to get you started.
 

Anchors

^

Start of string, or start of line in multi-line pattern

\A

Start of string

$

End of string, or end of line in multi-line pattern

\Z

End of string

\b

Word boundary

\B

Not word boundary

\<

Start of word

\>

End of word

Character Classes

\c

Control character

\s

White space

\S

Not white space

\d

Digit

\D

Not digit

\w

Word

\W

Not word

\x

Hexade­cimal digit

\O

Octal digit

POSIX

[:upper:]

Upper case letters

[:lower:]

Lower case letters

[:alpha:]

All letters

[:alnum:]

Digits and letters

[:digit:]

Digits

[:xdigit:]

Hexade­cimal digits

[:punct:]

Punctu­ation

[:blank:]

Space and tab

[:space:]

Blank characters

[:cntrl:]

Control characters

[:graph:]

Printed characters

[:print:]

Printed characters and spaces

[:word:]

Digits, letters and underscore

Assertions

?=

Lookahead assertion

?!

Negative lookahead

?<=

Lookbehind assertion

?!= or ?<!

Negative lookbehind

?>

Once-only Subexp­ression

?()

Condition [if then]

?()|

Condition [if then else]

?#

Comment

 

Quanti­fiers

*

0 or more

{3}

Exactly 3

+

1 or more

{3,}

3 or more

?

0 or 1

{3,5}

3, 4 or 5

Add a ? to a quantifier to make it ungreedy.

Escape Sequences

\

Escape following character

\Q

Begin literal sequence

\E

End literal sequence

"­Esc­api­ng" is a way of treating characters which have a special meaning in regular expres­sions literally, rather than as special charac­ters.

Common Metach­ara­cters

^

[

.

$

{

*

(

\

+

)

|

?

<

>

The escape character is usually \

Special Characters

\n

New line

\r

Carriage return

\t

Tab

\v

Vertical tab

\f

Form feed

\xxx

Octal character xxx

\xhh

Hex character hh

 

Groups and Ranges

.

Any character except new line (\n)

(a|b)

a or b

(...)

Group

(?:...)

Passive (non-c­apt­uring) group

[abc]

Range (a or b or c)

[^abc]

Not (a or b or c)

[a-q]

Lower case letter from a to q

[A-Q]

Upper case letter from A to Q

[0-7]

Digit from 0 to 7

\x

Group/­sub­pattern number "­x"

Ranges are inclusive.

Pattern Modifiers

g

Global match

i *

Case-i­nse­nsitive

m *

Multiple lines

s *

Treat string as single line

x *

Allow comments and whitespace in pattern

e *

Evaluate replac­ement

U *

Ungreedy pattern

* PCRE modifier

String Replac­ement

$n

nth non-pa­ssive group

$2

"­xyz­" in /^(abc­(xy­z))$/

$1

"­xyz­" in /^(?:a­bc)­(xyz)$/

$`

Before matched string

$'

After matched string

$+

Last matched string

$&

Entire matched string

Some regex implem­ent­ations use \ instead of $.

 

 

[출처]

https://www.cheatography.com/explore/popular/

http://emailregex.com/regular-expressions-cheat-sheet/

번호 제목 글쓴이 날짜 조회 수
54 export to excel(xlsx, xls), csv, txt file - 엑셀 파일로 저장 file taknim 2016.12.15 5091
» Regular Expressions Cheat Sheet - 정규표현식 치트 시트 taknim 2016.12.13 732
52 자바스크립트 클립보드 복사 (copy) taknim 2016.06.17 349
51 ip 국가/도시 코드(이름) 확인 (geoip) taknim 2015.02.24 2301
50 이메일, email 정규표현식 taknim 2015.02.24 2294
49 [google map api] 구글 맵스 API 로 지도 가져오기 taknim 2012.02.09 16939
48 [js] 사업자등록번호, 주민등록번호, 외국인등록번호 유효성 체크 taknim 2012.01.30 14062
47 [js] jquery 브라우저 버전 확인 자바스크립트 taknim 2012.01.10 12685
46 [js] showModalDialog Method taknim 2011.12.05 10083
45 [js & php] 비밀번호 유효성 체크 - 연속 문자, 같은 문자 taknim 2011.11.09 28396
44 navigator.userAgent 정리 taknim 2011.07.06 6613
43 [jQuery] 팝업창이나 하위프레임에서 상위 객체를 셀렉트 taknim 2011.06.07 8271
42 아이피 형식 체크 함수 taknim 2011.03.11 6574
41 모든 브라우저에 숫자만 입력받기 적용 taknim 2011.02.24 7281
40 jQuery 숫자만 입력 taknim 2010.10.27 12823
39 태그삭제하는 스크립트 taknim 2010.06.16 9841
38 javascript 에서 cookie 남기기 setcookie taknim 2010.04.22 11857
37 자바스크립트로 폰트 설치 유무 확인하기 taknim 2010.04.21 12061
36 한글 정규식 taknim 2010.02.19 9300
35 새 창에 form을 post로 전송하기 taknim 2009.09.16 10513