2015년 2월 12일 목요일

groovy 연습 4



// 2015-02-13 13:40:47 (금요일)

locationData = "Liverpool, England: 53d 25m 0s N 3d 0m 0s"
myRegularExpression = /([a-zA-Z]+), ([a-zA-Z]+): ([0-9]+). \
([0-9]+). ([0-9]+). ([A-Z]) ([0-9]+). ([0-9]+). ([0-9]+)./

matcher = ( locationData =~ myRegularExpression )

println locationData
println locationData.getClass()
println matcher.matches()
println matcher.getCount()
println matcher[0]
println matcher[0][0]
println matcher[0][1]
println matcher[0][6]

// 결과가 이차원배열에 들어간다는 사실.


// Non-matching group
names = [
    "Graham James Edward Miller",
    "Andrew Gregory Macintyre",
    "No MiddleName"
]

printClosure = {
    matcher = (it =~ /(.*?)(?: .*)* (.*)/)
    if ( matcher.matches())
        println( matcher[0][2]+", " + matcher[0][1])
}

names.each(printClosure)

// 문자열 바꾸기
excerpt = "At school, Harry had no one. Everybody knew that \
Dudley's gang hated that odd Harry Potter "+
          "in his baggy old clothes and broken glasses, \
and nobody liked to disagree with Dudley's gang.";


println excerpt
matcher = (excerpt =~ /Harry Potter/)
excerpt = matcher.replaceAll("Tanya Grotter")

matcher = (excerpt =~ /Harry/)
excerpt = matcher.replaceAll("Tanya")
println("Publish it! " + excerpt)

//
// Greedy operator
// Reluctant operator
//

Firefly Algorithms

firefly algorithm 001 Firefly Algorithms ¶ 반딧불 알고리즘 번역 요약 ¶ References [1] X. S. Y...