UltraEdit 정규식

Posted by Programmer™
2018. 2. 4. 20:07 카테고리 없음

텍스트 파일을 편집하다가 보면 특정 단어가 들어있는 줄을 삭제하고자 할때가 있다.

크기가 얼마 안되는 경우 수작업으로 할수도 있지만 파일크기가 큰 경우엔 일일이 수작업으로 하기엔 벅차다.

이 때 정규식을 사용하면 쉽게 할 수 있다.

아래 그림은 ipfilter.dat 의 파일 내용이다. Level1을 의미하는 [L1] 이 들어있는 줄을 전부 지우고자 한다.

먼저 마우스로 긁어서 아래 그림처럼 작업할려는 줄을 선택해준다.

 

Ctrl + R 키를 눌러서 Find what: 에

^.*L1.*\p 를 입력한다. Selected text 를 선택해주고 Regular expressions: 에 체크표시를 해준다.

정규식은 Perl, Unix, UltraEdit 중에서 하나를 선택할 수 있다.

그리고 마지막으로 Replace all 을 클릭한다.

아래 그림은 위 정규식 작업 결과이다. 보시는 것처럼 [L1] 이 들어있는 줄은 전부 삭제되었다.

 

 

Regular Expressions (Unix Syntax): 

Symbol

Function

\

Indicates the next character has a special meaning.  "n" on it's own matches the character "n".  "\n" matches a linefeed or newline character.  See examples below (\d, \f, \n etc).

^

Matches/anchors the beginning of line.

$

Matches/anchors the end of line.

*

Matches the preceding single character/character set zero or more times.

+

Matches one or more of the preceding single character/character set.  At least one occurrence of the preceding character or one of the characters in preceding character set must be found.

Matches any single character except a newline character.  Does not match repeated newlines.

(expression)

Brackets or tags an expression to use in the replace command.  A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.
 
 
The corresponding replacement expression is \x, for x in the range 1-9.  Example: If (h.*o) (f.*s) matches "hello folks", \2 \1 would replace it with "folks hello".

[xyz]

A character set.  Matches any characters between brackets.

[^xyz]

A negative character set.  Matches any characters NOT between brackets including newline characters.

\d

Matches a digit character.  Equivalent to [0-9].

\D

Matches a nondigit character.  Equivalent to [^0-9].

\f

Matches a form-feed character.

\n

Matches a linefeed character.

\r

Matches a carriage return character.

\s

Matches any whitespace including space, tab, form-feed, etc but not newline.

\S

Matches any non-whitespace character but not newline.

\t

Matches a tab character.

\v

Matches a vertical tab character.

\w

Matches any alphanumeric character including underscore.

\W

Matches any character except alphanumeric characters and underscore.

\p

Matches CR/LF (same as \r\n) to match a DOS line terminator.