티스토리 뷰

울트라에디터 정규식 표현들입니다.

아래 정규식 사용 방식을 이용해서 소스코드나 장문의 글들에서 불규칙적인 표현들의 전체를 쉽게 찾거나 바꿀수 있습니다.
아래 내용은 울트라 에디터 홈페이지에서 발췌한 글입니다.
자세한 내용은 아래 사이트를 참고하세요



Simple String Matching

Simple string matching is probably the most basic form of regular expressions but can allow you to quickly exploit different patterns so that you can search for more than one string at a time rather than doing multiple Find operations.

UltraEdit RegExp:

Find What: m?n
Matches: "man" and "men" but not "moon"

Find What: t*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").

Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"

UNIX RegExp:

Find What: m.n
Matches: "man" and "men" but not "moon"

Find What: t.*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").

Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"



Character Sets

A character set is a group of characters bounded by "[" and "]". These may be used to designate specific characters to be matched or ranges (i.e. [aeud], or [a-z]).

UltraEdit RegExp:

Find What: [aeiou]
Matches: every vowel

NOTE: Regular Expressions in UltraEdit are not case-sensitive unless Match Case is selected in the Find dialog. 

Find What: [,.^?]
Matches: a literal ",", "." or "?".

Because the "?" is a symbol used in expressions it must be "escaped" for the literal character to be matched rather than interpreted as an expression.

Find What: [0-9a-z]
Matches: any digit or letter

Find What: [~0-9]
Matches: any character except a digit (~ means NOT the following)

UNIX RegExp:

Find What: [aeiou]
Matches: every vowel

Find What: [,\.?]
Matches: a literal ",", "." or "?".

Because the "." is a symbol used in expressions it must be "escaped" for the literal character to be matched rather than interpreted as an expression.

Find What: [0-9a-z]
Matches: any digit or letter

Find What: [^0-9]
Matches: any character except a digit (^ means NOT the following)



OR Expressions

Currently UltraEdit only allows for the specification of two operands for an OR expression. You may search for an expression A or B as follows:

UltraEdit RegExp:

Find What: ^{John^}^{Tom^}

UNIX RegExp:

Find What: (John|Tom)

There should be nothing between the two expressions. You may combine A or B and C or D in the same search as follows:

UltraEdit RegExp:

Find What: ^{John^}^{Tom^} ^{Smith^}^{Jones^}

UNIX RegExp:

Find What: (John|Tom) (Smith|Jone)

This will search for "John" or "Tom" followed by "Smith" or "Jones".



Deleting Blank Lines

With Regular Expressions selected in the Replace dialog this will match the a CR/LF (DOS line terminator) immediately followed by the end of a line (i.e., a blank line) and replace it with nothing, effectively deleting it:

UltraEdit RegExp:

Find What: ^p$
Replace With: (literally nothing)

UNIX RegExp:

Find What: \p$
Replace With: (literally nothing)



Reformatting Text With Tagged Expressions

Example 1:

Tagged expressions may be used to mark various data members so that they may be reorganized, reformatting the data. For example, it might be useful to be able to rearrange:

John Smith, 385 Central Ave., Cincinnati, OH, 45238

into:

45238, Smith, John, 385 Central Ave., Cincinnati, OH

UltraEdit RegExp:

Find What: %^([a-z]+^) ^([a-z]+^), ^(*^), ^(*^), ^(*^), ^([0-9]+^)
Replace With: ^6, ^2, ^1, ^3, ^4, ^5

UNIX RegExp:

Find What: ^([a-z]+) ([a-z]+), (.*), (.*), (.*), ([0-9]+)
Replace With: \6, \2, \1, \3, \4, \5


Example 2:

If you have a web-based registration system it might be useful to rearrange the order data into a format easily used by a database:

name = John Smith
address1 = 385 Central Ave.
address2 = 
city = Cincinnati
state = OH
zip = 45238

into:

John Smith, 385 Central Ave.,, Cincinnati, OH, 45238,

This can be done with the following expression:

UltraEdit RegExp:

Find What: name = ^([a-z ]+^)^paddress1 = ^([a-z 0-9.,]+^)^paddress2 = ^([a-z 0-9.,]++^)^pcity = ^([a-z]+^)^pstate = ^([a-z]+^)^pzip = ^([0-9^-]+^)
Replace With:^1, ^2, ^3, ^4, ^5, ^6

UNIX RegExp:

Find What: name = ([a-z ]+)\paddress1 = ([a-z 0-9.,]+)\paddress2 = ([a-z 0-9.,]*)\pcity = ([a-z]+)\pstate = ([a-z]+)\pzip = ([0-9^-]+)
Replace With:\1, \2, \3, \4, \5, \6

댓글

파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음



Total
Today
Yesterday
최근에 달린 댓글