본문 바로가기

이전글

Regular Expressions Tutorial

Regular Expressions Tutorial

정규 표현 튜터리얼 목차

 

 

 

머리말

: 본 정규식 표현 튜터리얼은 총 26종류의 분류로 나누어져 주로 예제 형식으로 구성되어 있으며

작성자 본인의 지식 습득과 다른 많은 분들에게도 정규식( 정규 표현, 정규 표현식, regular expression )을 이해하는데 도움이 되고자 하는것이 취지입니다.

현재 해당 사이트( http://www.zvon.org/ )에서 14개국어를 부분적으로  지원하고 있으나, 안타깝게도 한국어 지원이 이루어지지 않습니다. 비교적 해석하기 쉬운 영어로 작성되어져 있기는 하지만, 한국어 번역 및 개인적인 설명들을 직접 붙여 보았습니다. 목차는 아래와 같으며 번역의 정확성 보다는 개념이해에 중점을 두었으므로 양해 하시기 바랍니다. 많은 분들에게 도움이 되었으면 좋겠습니다. 감사합니다.

 

참고 : 문의사항은 블로그 http://darkhorse.tistory.com/ 로 방문하셔서 원하는 방식으로 게시물을 남겨 주시기 바랍니다.

 


 

Contents 목차

Example 1

Regular expressions are case sensitive. Therefore Case 1 will find the specified text, but Case 2 will not.

Example 2

Each character inside the search pattern is significant including whitespace characters (space, tab, new line).

Example 3

Some characters have special meanings. Character ^ matches the beginning of the line (Case 1) while dollar sign $ the end of the line (Case 2)

Example 4

If literal value of a special character is required, it must be escaped with a backslash \. Case 1 does not match anything as both characters a special, Case 2 matches all $, Case 3 matches $ only if it is the first and Case 4 the last character. Backslash has special meaning and must be also escaped for literal use (Case 5).

Example 5

Point . matches any character.

Example 6

The point must be escaped if literal meaning is required.

Example 7

Inside square brackets "[]" a list of characters can be provided. The expression matches if any of these characters is found. The order of characters is insignificant.(Case 3)

Example 8

A range of characters can be specified with [ - ] syntax. Case 1 and Case 2 are equivalent. Several ranges can be given in one expression (Case 5).

Example 9

If a character class starts with ^, then specified characters will not be selected

Example 10

Alternating text can be enclosed in parentheses and alternatives separated with |.

Example 11

Quantifiers specify how many times a character can occur. Star * (Case 1) matches zero or more times, plus + (Case 2) once or more times and question mark ? (Case 3) zero or once.

Example 12

Several examples of "*" quantifier

Example 13

Several examples of "+" quantifier

Example 14

Several examples of "?" quantifier

Example 15

Curly brackets enable precise specification of character repetitions. {m} matches precisely m times (Case 1), {m,n} matches minimaly m times and maximaly n times (Case 2) and {m,}matches minimaly m times(Case 3). Im dritten Fall werden also alle Wörter gefunden, die mindestens 3 Zeichen zwischen a-z besitzen besitzen.

Example 16

Quantifiers "*", "+", and "?" are special cases of the bracket notation. "*" is equivalent to {0,} (Case 1, Case 2), "+" to {1,} (Case 3, Case 4), and "?" to {0,1} (Case 5, Case 6).

Example 17

By default any subpattern matches as many times as possible. This behaviour is changed to matching the minimum number if quantifier is followed with the question mark. Compare "*" (Case 1) with "*?" (Case 2), "+" (Case 3) with "+?" (Case 4), and "?" (Case 5) with "??" (Case 6).

Example 18

\w matches any word character ( alphanumeric plus "_" ). In some languages these letter abbreviations are not recognized. Use character classes ("[A-z0-9_]") instead (Case 5).

Example 19

\W matches any non-word character (everything but alphanumeric plus "_" ). Compare Case 1 and Case 2. It is equivalent to "[^A-z0-9_]".

Example 20

\s matches white space characters: space, new line and tab. \S matches any non-whitespace character.

Example 21

\d matches any digit and \D anything else. Compare Case 1 and Case 2. Use "[0-9]" if your programming language does not support this abbreviation (Case 3).

Example 22

\b matches a word boundary. A word boundary (\b) is defined as a spot between two characters that has a \w on one side of it and a \W on the other side of it (in either order).

Example 23

\B matches a non (word boundary). A word boundary (\b) is defined as a spot between two characters that has a \w on one side of it and a \W on the other side of it (in either order).

Example 24

\A matches the beginning of string. It is similar to ^, but ^ will match after each newline, if multiline strings are considered. Similarly, \Z matches only at the end of the string or before newline at the end of it. It is similar to $, but $ will match before each newline.

Example 25

(?=<pattern>) will look ahead if the pattern exists, but will not include it in the hit.

Example 26

(?!<pattern>) will look ahead if the pattern exists. If it does there will be no hit.

 


 

Regular Expressions Tutorial 정규 표현 튜터리얼 01/26

 

Description 설명

Regular expressions are case sensitive. Therefore Case 1-1 will find the specified text, but Case 1-2 will not.

정규 표현이  민감한 경우의 예를 보여준다. 예제 1-1에서는 명확하게 찾아지는 문장이지만, 예제 1-2에서는 찾을 수 없다.

 

Source 소스

 

Hello, world!

 

Case 1-1 예제 1-1

 

Regular Expression
정규 표현 :

Hello

First match
처음 검색 결과:

Hello, world!

All matches
전체 검색 결과:

Hello, world!

 match : 1

: Hello 검색 성공. 예제 소스에서 일치(match)하는 문장에 형광펜 표시를 하였다.

 

Case 1-2 예제 1-2

 

Regular Expression
정규 표현 :

hello

First match
처음 검색 결과:

Hello, world!

All matches
전체 검색 결과:

Hello, world!

match : 0

 : hello를 찾을 수 없다. hello Hello의 대소문자를 눈여겨 보라.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 02/26

 

Description 설명

Each character inside the search pattern is significant including whitespace characters (space, tab, new line).

예제 1과 같이 대소문자 뿐만 아니라 스페이스, , 줄바꿈 또한 민감하게 적용이 된다.

 

Source 소스

 

Hello, world!

 

Case 2-1 예제 2-1

 

Regular Expression
정규 표현 :

Hello, world

First match
처음 검색 결과:

Hello, world!

All matches
전체 검색 결과:

Hello, world!

match : 1

: Hello, world 검색 성공.

 

Case 2-2 예제 2-2

 

Regular Expression
정규 표현 :

Hello,    world

First match
처음 검색 결과:

Hello, world!

All matches
전체 검색 결과:

Hello, world!

match : 0

 : Hello,    world로 검색하게 되면 Hello, world는 찾을 수 없다. 스페이스(띄움)에 유의하라.

 


 

Regular Expressions Tutorial 정규 표현 튜터리얼 03/26

 

Description 설명

Some characters have special meanings. Character ^ matches the beginning of the line (Case 3-1) while dollar sign $ the end of the line (Case 3-2)

어떤 문자는 특수한 의미를 가지고 있다. 3-1에서는 ^문자를 사용하여 라인의 시작부분을 찾고, 3-2에서는 $문자를 사용하여 라인의 끝부분을 찾는다.

 

Source 소스

 

who is who

 

Case 3-1 예제 3-1

 

Regular Expression
정규 표현 :

^who

First match
처음 검색 결과:

who is who

All matches
전체 검색 결과:

who is who

match : 1

: ^문자를 사용하여 라인에서 who로 시작하는 문자 검색

 

Case 3-2 예제 3-2

 

Regular Expression
정규 표현 :

who$

First match
처음 검색 결과:

who is who

All matches
전체 검색 결과:

who is who

match : 1

 : $문자를 사용하여 라인에서 who로 끝나는 문자 검색


 

Regular Expressions Tutorial 정규 표현 튜터리얼 04/26

 

Description 설명

특수문자를 필요로 할 경우, 백슬래쉬 문자인 \를 사용하여야 한다.

예제 4-1과 같이 사용하면 라인에서 $ 시작하는 문장을 찾을 수 없다. 예제 4-2에서는 모든 $문자를, 4-3에서는 $로시작하는 문자를, 4-4에서는 $로 끝나는 문자를 찾는다.

백슬래쉬는 특수한 의미를 가지고 있고  4-5와 같이 백슬래쉬문자를 검색하기위해 한번더 백슬래쉬를 사용하였다.

 

Source 소스

 

$12$ \-\ $25$

 

Case 4-1 예제 4-1

 

Regular Expression
정규 표현 :

^$

First match
처음 검색 결과:

$12$ \-\ $25$

All matches
전체 검색 결과:

$12$ \-\ $25$

match : 0

: $로 시작하는 라인의 첫번째 문장을 찾을 수 없다. 특수문자인 백슬래쉬 \를 사용해야 할 것 같다.

 

Case 4-2 예제 4-2

 

Regular Expression
정규 표현 :

\$

First match
처음 검색 결과:

$12$ \-\ $25$

All matches
전체 검색 결과:

$12$ \-\ $25$

match : 4

 : 백슬래쉬 \를 사용하여 모든 $문자를 검색 가능하다.

 

Case 4-3 예제 4-3

 

Regular Expression
정규 표현 :

^\$

First match
처음 검색 결과:

$12$ \-\ $25$

All matches
전체 검색 결과:

$12$ \-\ $25$

match : 0

 : $로 시작하는 라인의 첫 문장을 찾았다.

 

Case 4-4 예제 4-4

 

Regular Expression
정규 표현 :

\$$

First match
처음 검색 결과:

$12$ \-\ $25$

All matches
전체 검색 결과:

$12$ \-\ $25$

match : 1

 : $로 끝나는 라인의 마지막 문장을 찾았다.

 

Case 4-5 예제 4-5

 

Regular Expression
정규 표현 :

\\

First match
처음 검색 결과:

$12$ \-\ $25$

All matches
전체 검색 결과:

$12$ \-\ $25$

match : 2

 : 모든 \문자를 찾았다.

Regular Expressions Tutorial 정규 표현 튜터리얼 05/26

 

Description 설명

Point . matches any character.

점은 어떤(any) 문자를 의미한다. 점하나의 의미가 하나의 문자이다.

 

Source 소스

 

Regular expressions are powerful!!!

 

Case 5-1 예제 5-1

 

Regular Expression
정규 표현 :

.

First match
처음 검색 결과:

Regular expressions are powerful!!!

All matches
전체 검색 결과:

Regular expressions are powerful!!!

match : all

: 점 하나로 하나(any)의 문자를 찾는다.

 

Case 5-2 예제 5-2

 

Regular Expression
정규 표현 :

......

First match
처음 검색 결과:

Regular expressions are powerful!!!

All matches
전체 검색 결과:

Regular expressions are powerful!!!

match : 5

 : 점이 6개이다. 6개의 문자씩 찾는다. 전체 검색 결과에도 5개의 문장(6개의 문자로 이루어진 문장)이 검색되었다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 06/26

 

Description 설명

The point must be escaped if literal meaning is required.

(.)이라는 문자를 검색하기 위해서는 4장에서 배운 것 처럼 역슬래쉬 \를 사용하여야 한다. 그렇지 않으면 점은 하나의 문자로 인식한다.

 

Source 소스

 

O.K.

 

Case 6-1 예제 6-1

 

Regular Expression
정규 표현 :

.

First match
처음 검색 결과:

O.K.

All matches
전체 검색 결과:

O.K.

match : 4

: 점 하나로 하나(any)의 문자를 찾는다. 전체검색결과 4개의 문자를 찾았다.

 

Case 6-2 예제 6-2

 

Regular Expression
정규 표현 :

\.

First match
처음 검색 결과:

O.K.

All matches
전체 검색 결과:

O.K.

match : 2

 : 역슬래쉬 \를 사용하여 점(.)이라는 문자를 찾는다. 전체 검색결과 2개의 문자를 찾았다.

 

 

Case 6-3 예제 6-3

 

Regular Expression
정규 표현 :

\..\.

First match
처음 검색 결과:

O.K.

All matches
전체 검색 결과:

O.K.

match : 1

 : 점과 하나 의문자와 점( + 문자 + )으로 구성된 문자를 찾는다.

 


 

Regular Expressions Tutorial 정규 표현 튜터리얼 07/26

 

Description 설명

Inside square brackets "[]" a list of characters can be provided. The expression matches if any of these characters is found. The order of characters is insignificant.(Case 7-3)

대괄호 "[]"안에 문자 리스트를 사용하게끔 해주었다. 문자들중 하나라도 맞으면 적용이 된다. 문자의 명령은 부분적이다?

이래서 번역보다는 설명인것 같다 --> "대괄호안에 있는 문자중 하나의 문자를 찾아준다"라는 의미이다.

 

Source 소스

 

How do you do?

 

Case 7-1 예제 7-1

 

Regular Expression
정규 표현 :

[oyu]

First match
처음 검색 결과:

How do you do?

All matches
전체 검색 결과:

How do you do?

match : 6

: o, y, u 중 하나의 문자를 찾는다.

 

Case 7-2 예제 7-2

 

Regular Expression
정규 표현 :

[dH].

First match
처음 검색 결과:

How do you do?

All matches
전체 검색 결과:

How do you do?

match : 3

 : d로 또는 H로 시작하고 다음문자(점은 문자하나를 의미)까지 포함해서 찾는다.

 

Case 7-3 예제 7-3

 

Regular Expression
정규 표현 :

[owy][yow]

First match
처음 검색 결과:

How do you do?

All matches
전체 검색 결과:

How do you do?

match : 2

 : 마찬가지로 대괄호가 두번 열리고 닫혔으니 두개의 문자를 찾는것이고, 각각은 대괄호 안에 해당하는 문자가 하나 있어야 한다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 08/26

 

Description 설명

A range of characters can be specified with [ - ] syntax. Case 1 and Case 2 are equivalent. Several ranges can be given in one expression (Case 8-5).

대괄호 안에 -를 사용하여 문자의 범위를 지정할 수 있다. 예제 8-1 8-2는 사실상 같은 의미이다. 몇몇의 범위는 예제 8-5 와 같이 하나의 표현으로 나타내지기도 한다.

 

Source 소스

 

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

 소스가 길어졌다. 찾는 재미가 생기는거다.

 

Case 8-1 예제 8-1

 

Regular Expression
정규 표현 :

[C-K]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

match : 9

: 알파벳 순서대로 C부터 K까지 하나의 문자를 찾아준다. 예제 8-2 -를 이용한 문법을 사용하여 줄여놓은 것이다

 

Case 8-2 예제 8-2

 

Regular Expression
정규 표현 :

[CDEFGHIJK]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

match : 9

 : 지금은 C부터 K까지 짧은 길이이지만, 충분히 길어질 경우 이와 같은 표현은 8-1과 같이 표현하는게 효율적일 것이다.

 

Case 8-3 예제 8-3

 

Regular Expression
정규 표현 :

[a-d]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

match : 4

 : a부터 d까지 하나의 문자를 찾아준다. 예제 1-2에서 이야기한것 처럼 대소문자에 까다롭다.

 

Case 8-4 예제 8-4

 

Regular Expression
정규 표현 :

[2-6]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

match : 5

: 숫자도 문자와 같은 규칙이 적용된다. 2부터 6까지 찾는다.

 

Case 8-5 예제 8-5

 

Regular Expression
정규 표현 :

[C-Ka-d2-6]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

match : 18

 : 대괄호 사이에는 예제와 같이 조합도 가능하다. 몇몇의 범위를 하나의 표현으로 나타낸다는 말이 바로 이것이다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 09/26

 

Description 설명

If a character class starts with ^, then specified characters will not be selected.

대괄호 안의 문자 리스트에 ^문자가 들어가면 포함하지 않는다는 의미이다. , ^ not의 의미인 것이다.

 

Source 소스

 

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789

 

Case 9-1 예제 9-1

 

Regular Expression
정규 표현 :

[^CDghi45]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789

: CDghi45를 제외한 나머지 문자를 찾는다. 이번엔 검색된 문자에 하나씩 반전된 색표시는 생략하기로 하겠다.

 

Case 9-2 예제 9-2

 

Regular Expression
정규 표현 :

[^W-Z]

First match
처음 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789

All matches
전체 검색 결과:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789

 : 마찬가지로 제외할 문자리스트에서도 -를 사용하여 범위를 지정할 수 있다. [^WXYZ] 와 같은 표현이다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 10/26

 

Description 설명

Alternating text can be enclosed in parentheses and alternatives separated with |.

선택적인 문장은 ()괄호속에 있고, |문자(shift+역슬래쉬)를 사용하여 선택되어진다. |문자로 구분되어 진다는 것이다.

 

Source 소스

 

Monday Tuesday Friday

 

Case 10-1 예제 10-1

 

Regular Expression
정규 표현 :

(on|ues|rida)

First match
처음 검색 결과:

Monday Tuesday Friday

All matches
전체 검색 결과:

Monday Tuesday Friday

: on ues 또는 rida가 포함된 문장을 찾는다. 대괄호 사용시와 달리 소괄호 사용시에는 문자(Character)단위가 아니라 문장(String or Text) 단위임을 유념한다.

 

Case 10-2 예제 10-2

 

Regular Expression
정규 표현 :

(Mon|Tues|Fri)day

First match
처음 검색 결과:

Monday Tuesday Friday

All matches
전체 검색 결과:

Monday Tuesday Friday

 : 괄호 뒷부분에 문장을 덧붙여서 검색이 가능하다. ~~ 유용하게 쓰이겠다 싶은게 나오기 시작한다.

 

 

Case 10-3 예제 10-3

 

Regular Expression
정규 표현 :

..(id|esd|nd)ay

First match
처음 검색 결과:

Monday Tuesday Friday

All matches
전체 검색 결과:

Monday Tuesday Friday

 : 마찬가지로 괄호 앞부분에도 문장을 덧붙여서 검색이 가능하다. 점 두 개는 두 개의 문자(Character)라는 것을 잊지 말자.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 11/26

 

Description 설명

Quantifiers specify how many times a character can occur. Star * (Case 11-1) matches zero or more times, plus + (Case 11-2) once or more times and question mark ? (Case 11-3) zero or once.

지정된 기호들에 몇번 문자가 발생되냐를 명시화한다. * 0또는 그이상을, + 1또는 그이상을, ? 0또는 1을 의미한다.

무슨 말이냐 하면? 이번 예제는 말로 설명하기 보다는 예제로 습득하기 바란다. 훨씩 직관적일 것이다.

 

Source 소스

 

aabc abc bc

 

Case 11-1 예제 11-1

 

Regular Expression
정규 표현 :

a*b

First match
처음 검색 결과:

aabc abc bc

All matches
전체 검색 결과:

aabc abc bc

: a문자는 0또는 그이상 있어야하고 b문자는 하나있는 문장을 찾는다.

 a*b라는 표현은 b, ab, aab, aaab, aaaab, aaaaab ... 형식의 모든 문장을 찾는 것이 가능하다.  

 

Case 11-2 예제 11-2

 

Regular Expression
정규 표현 :

a+b

First match
처음 검색 결과:

aabc abc bc

All matches
전체 검색 결과:

aabc abc bc

 : a*b 표현과 유사하지만 a가 없을때 허용되었던것이

   a+b 표현에서는 a가 적어도 1개는 있어야 한다.  ab, aab, aaab, aaaab, aaaaab ... 형식의 모든 문장을 찾는 것이 가능하다.

 

Case 11-3 예제 11-3

 

Regular Expression
정규 표현 :

a?b

First match
처음 검색 결과:

aabc abc bc

All matches
전체 검색 결과:

aabc abc bc

 : ?를 사용하면 0개 또는 1개이다. 감이 잡혔다면


 

Regular Expressions Tutorial 정규 표현 튜터리얼 12/26

 

Description 설명

Several examples of "*" quantifier.

별표(*)가 들어가는 몇몇 예문들이다.

 

Source 소스

 

-@- *** -- "*" -- **-a-A-* -@ -AA--**

 이번 소스는 좀 부족한듯해서 조금 덧붙였다.

 

Case 12-1 예제 12-1

 

Regular Expression
정규 표현 :

.*

First match
처음 검색 결과:

-@- *** -- "*" -- **-a-A-* -@ -AA--**

All matches
전체 검색 결과:

-@- *** -- "*" -- **-a-A-* -@ ---AA--**

: (.)은 한개의 문자이고, 별표(*) 0개 또는 그이상이라고 배웠다. 어떤(any)문자든 몇개있던 상관 없다는거다.

 이는 전체 선택과 같은데 쓰임은 거의 없으나 예제만으로 이해하고 넘어가자.   이번에도 각각의 선택에 색반전 효과는 생략하도록 하겠다.

 

Case 12-2 예제 12-2

 

Regular Expression
정규 표현 :

-A*-

First match
처음 검색 결과:

-@- *** -- "*" -- **-a-A-* -@ -AA--**

All matches
전체 검색 결과:

-@- *** -- "*" -- **-a-A-* -@ -AA--**

 : A 0개 이거나 그이상 있는 문장을 찾는다.

 

Case 12-3 예제 12-3

 

Regular Expression
정규 표현 :

[\*"]*

First match
처음 검색 결과:

-@- *** -- "*" -- **-a-A-* -@ -AA--**

All matches
전체 검색 결과:

-@- *** -- "*" -- **-a-A-* -@ -AA--**

 : 뒤로 가서 예제를 다시 보게 만드는 예제이다. 암기력이 좋은 분은 한번에 이해하실지도 모르겠다.

  * " 0개 또는 그 이상으로 구성된 문장을 찾는다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 13/26

 

Description 설명

Several examples of "+" quantifier.

+가 들어가는 몇몇 예문들이다.

 

 

Source 소스

 

-@@@- * ** - - "*" -- * ** -@@@-

 

 

Case 13-1 예제 13-1

 

Regular Expression
정규 표현 :

\*+

First match
처음 검색 결과:

-@@@- * ** - - "*" -- * ** -@@@-

All matches
전체 검색 결과:

-@@@- * ** - - "*" -- * ** -@@@-

: *문자가 1개 또는 그 이상이 있는 문장을 찾는다.

 

 

Case 13-2 예제 13-2

 

Regular Expression
정규 표현 :

-@+-

First match
처음 검색 결과:

-@@@- * ** - - "*" -- * ** -@@@-

All matches
전체 검색 결과:

-@@@- * ** - - "*" -- * ** -@@@-

 : -문자와 -문자 사이에 @문자가 1개 또는 그 이상 있는 문장을 찾는다.

 

 

Case 13-3 예제 13-3

 

Regular Expression
정규 표현 :

[^ ]+

First match
처음 검색 결과:

-@@@- * ** - - "*" -- * ** -@@@-

All matches
전체 검색 결과:

-@@@- * ** - - "*" -- * ** -@@@-

 : ^문자 다음에 스페이스바가 있음에 유념해야 한다. 스페이스바가 없는 문자 하나 또는 그 이상인 문장을 찾는다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 14/26

 

Description 설명

Several examples of "?" quantifier.

?가 들어가는 몇몇 예문들이다.

 

 

Source 소스

 

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

 

 

Case 14-1 예제 14-1

 

Regular Expression
정규 표현 :

-X?XX?X

First match
처음 검색 결과:

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

All matches
전체 검색 결과:

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

: 복잡하게 보이는데 천천히 살펴보자. -XX, -XXX, -XXXX 을 찾는 표현이다.

 

 

Case 14-2 예제 14-2

 

Regular Expression
정규 표현 :

-@?@?@?-

First match
처음 검색 결과:

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

All matches
전체 검색 결과:

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

 : 14-1과 유사하다. -@@@@-는 선택되지 않음을 유의하라.

 

 

Case 14-3 예제 14-3

 

Regular Expression
정규 표현 :

[^@]@?@

First match
처음 검색 결과:

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

All matches
전체 검색 결과:

--XX-@-XX-@@-XX-@@@-XX-@@@@-XX-@@-@@-

 : @로 시작하는 어떠한 문자는 제외한 어떤 문자와 @?@ 의 조합이다.

   소스를 복사해서 직접 어떠한 문장이 선택되어 지는지 본인이 확인해 보아야 한다.

   확인 후 오답이 나왔다면 선택되지 않은 @@ 문장에 대해서 곰곰히 생각해보자. 6개의 문장이 선택되었다.


 

Regular Expressions Tutorial 정규 표현 튜터리얼 15/26

 

Description 설명

Curly brackets enable precise specification of character repetitions. {m} matches precisely m times (Case 15-1), {m,n} matches minimaly m times and maximaly n times (Case 15-2) and {m,}matches minimaly m times(Case 15-3). Im dritten Fall werden also alle Wörter gefunden, die mindestens 3 Zeichen zwischen a-z besitzen besitzen.

중괄호는 문자 반복의 명확한 설명을 가능하게 한다. 15-1 예제에서 {m} 표현은 정확하게 m번 일치하는것을 의미한다. 15-2 예제와 15-3 예제에서 {m,n} 표현은 최소 m, 최대 n번 일치하는 것을 의미한다. " ... ... ". 독일어 같다. 갑자기 해석이 안된다. 최대 14개국어로 번역되는 곳에서 퍼온글인데 한국어가 지원이 안된다니. 안타깝다.

KOREAN 파워가 이리 약하단 말이냐.  어쩔수 없이 예제를 보고서 이해를 하도록 하자.

 

Source 소스

 

One ring to bring them all and in the darkness bind them

 

Case 15-1 예제 15-1

 

Regular Expression
정규 표현 :

.{5}

First match
처음 검색 결과:

One ring to bring them all and in the darkness bind them

All matches
전체 검색 결과:

One ring to bring them all and in the darkness bind them

: 어떤 문자 5개로 이루어진 문장을 표현하였다. 11번 찾아지고 마지막에 한글자가 남았다.

 

Case 15-2 예제 15-2

 

Regular Expression
정규 표현 :

[els]{1,3}

First match
처음 검색 결과:

One ring to bring them all and in the darkness bind them

All matches
전체 검색 결과:

One ring to bring them all and in the darkness bind them

 : e, l, s 문자로 구성되어야 하고 최소 1글자 최대 3글자를 표현하였다.

 

 

Case 15-3 예제 15-3

 

Regular Expression
정규 표현 :

[a-z]{3,}

First match
처음 검색 결과:

One ring to bring them all and in the darkness bind them

All matches
전체 검색 결과:

One ring to bring them all and in the darkness bind them

 : a-z. , 소문자로 구성되어야 하고 최소 3개의 문자가 되어야 한다.