메뉴 건너뛰기

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/

번호 제목 글쓴이 날짜 조회 수
473 유용한 함수 pack, unpack, ip2long, long2ip taknim 2009.01.13 33346
472 해커들을 위한 CMD 툴 모음 file taknim 2008.05.22 32564
471 [js & php] 비밀번호 유효성 체크 - 연속 문자, 같은 문자 taknim 2011.11.09 28101
470 [Oracle] ORA-00600, ORA-06544, ORA-06553 오류 발생시 taknim 2009.06.09 23834
469 리눅스 콘솔 단축키 taknim 2009.07.06 21930
468 리눅스 split | 파일 사이즈, 라인 단위 자르기 taknim 2008.06.19 20595
467 mcrypt 암호화/복호화 AES/CBC/PKCS5/PKCS7/PADDING [1] taknim 2010.03.19 19439
466 최고의 웹디자인용 작은 아이콘 다운로드 사이트 모음 : Best Small Icon Sites taknim 2007.07.11 18938
465 [mysql] 동적 쿼리 생성시 변수를 대입하거나 값을 받아오기 taknim 2009.08.17 17168
464 [MSSQL] MS-SQL 동적쿼리 이용하기 taknim 2009.12.28 16962
463 [google map api] 구글 맵스 API 로 지도 가져오기 taknim 2012.02.09 16903
462 [C/C++] prnitf 역슬래쉬 문자 taknim 2008.11.28 16248
461 EUC-KR <-> UTF-8 상호변환 하기 (문자셋charset 변환) taknim 2008.05.27 16113
460 [oracle] isqlplus 에서 특수문자(&) 입력하는 방법 taknim 2012.08.10 16050
459 [mysql] mysqlbinlog 실행시 캐릭터셋(utf8) 오류 taknim 2009.08.25 15753
458 [Oracle] DBNEWID Utility - DBNAME,DBID변경하기 taknim 2009.07.06 15572
457 inode 개념 taknim 2008.07.08 15366
456 UTF-8 을 이용해서 다국어버젼 웹사이트 개발시 고려사항 taknim 2008.10.17 15298
455 누구나 다 아는 네트워크(소켓) 통신시의 함수 pack과 unpack taknim 2008.05.17 14599
454 Postfix SMTP 서버를 이용한 IPv6 메일(SMTP) 서버 구성 taknim 2008.02.15 14443