Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Groovy는 <span style="text-decoration: underline;">~"..."</span> 표현을 통해 정규식을 언어 차원에서 지원하고 있습니다. 이 표현식은 컴파일시 주어진 문자열에 대한 자바 Pattern 객체로 변환됩니다. Groovy는 또한 Matcher를 생성하기 위한 =~ 연산자와 문자열이 정규식 패턴에 일치하는지를 검사하기 위한 ==~ 연산자를 제공합니다.</p> <p>JSR-03 릴리즈 이후부터는, Matcher가 그룹을 포함하고 있는 경우 matcher[index] 는 일치된 문자열 혹은 일치된 그룹 문자열들의 List를 담고 있습니다.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import java.util.regex.Matcher import java.util.regex.Pattern assert "cheesecheese" =~ "cheese" assert "cheesecheese" =~ /cheese/ assert "cheese" == /cheese/ /*둘 다 String 표현식입니다*/ // 정규식 Pattern을 만들어봅시다 def pattern = ~/foo/ assert pattern instanceof Pattern assert pattern.matcher("foo").matches() // 이번에는 Matcher를 만들고 있습니다 def matcher = "cheesecheese" =~ /cheese/ assert matcher instanceof Matcher answer = matcher.replaceAll("edam") // 문자열 치환 def cheese = ("cheesecheese" =~ /cheese/).replaceFirst("nice") assert cheese == "nicecheese" // 그룹 시연. // 그룹을 포함하고 있는 패턴에 대해 match를 할 수 있습니다. 우선 자바 API를 이용하거나 // =~ 연산자를 이용해서 Matcher 객체를 만들어야 합니다. 그 다음에는 일치하는 부분을 // 찾아내기 위해 Matcher를 인덱싱 합니다. // matcher[0][1] 은 전체 패턴에서 0번째 일치하는 부분 중 1번째 그룹을 의미합니다: def m = "foobarfoo" =~ /o(b.*r)f/ assert m[0][1] == "bar" // 더 보기 좋은 그룹 시연. matcher = "\$abc." =~ "\\\$(.*)\\." matcher.matches(); // 한번 호출되어야 함 [질문: 이 문장이 정말 true 인가요? jsr-04 에서 테스트해보았는데 false 였습니다.] assert matcher.group(1) == "abc" // 0이 아니라 1 // assert matcher[1] == "abc" // jsr-03-release 이전에는 true assert matcher[0] == ["\$abc.", "abc"] // jsr-03-release 부터는 이게 true assert matcher[0][1] == "abc" // jsr-03-release 부터는 이것도 true </pre></td></tr></table> <p>패턴은 "/" 구분자로 표현될 수도 있습니다. 그렇게 하면 두 개의 역슬래시를 이용해서 이스케입을 처리할 필요가 없습니다.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def matcher = "\$abc." =~ /\$(.*)\./ assert "\\\$(.*)\\." == /\$(.*)\./ matcher.matches(); // 한번 호출되어야 함 assert matcher.group(1) == "abc" // 0이 아니라 1 // assert matcher[1] == "abc" // jsr-03-release 이전에는 true assert matcher[0] == ["\$abc.", "abc"] // jsr-03-release 부터는 이게 true assert matcher[0][1] == "abc" // jsr-03-release 부터는 이것도 true </pre></td></tr></table> <p>Matcher는 <strong>find</strong> 메서드를 호출하면 boolean으로 변환되기 때문에 if 나 while 등에서 조건식으로 쓰일 때 =~ 연산자는 Perl의 =~ 연산자와 일관성을 유지합니다. 더 제한적인 ==~ 연산자는 전체 문자열이 일치하는지를 검사합니다.</p> <p>정규식 지원은 자바 API를 이용하고 있으므로 자세한 문서는 <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html">여기</a> 를 참고하세요.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced