文字列からの情報抽出
Posted feedbacks - awk
とりあえず動くコードをup。 最近のgawkだともっと効率の良い書き方ができるような気がします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | {
s = $0
while (match(s,/[a-z]+(-hidden)?(-small|-big)?\.[a-z]+/)) {
matched = substr(s,RSTART,RLENGTH)
s = substr(s,RSTART+RLENGTH+1)
hyphen = index(matched,"-")
period = index(matched,".")
if (hyphen > 0) {
name = substr(matched, 1, hyphen-1)
extra = substr(matched, hyphen, period - hyphen)
hidden = (extra ~ /-hidden/) ? "True" : "False"
if (extra ~ /-small/) size = "small"
else if (extra ~ /-big/) size = "big"
else size = "normal"
ext = substr(matched, period+1)
} else {
name = substr(matched, 1, period-1)
hidden = "False"
size = "normal"
ext = substr(matched, period+1)
}
printf("name:'%s', ext:'%s', size: %s hidden: %s\n", name, ext, size, hidden)
}
}
|


にしお
#3407()
Rating0/0=0.00
サンプル入力
サンプル出力
探すべき文字列は下の条件を満たします
出力は以下の条件を満たす必要があります
このお題は、正規表現のグループに名前をつけて連想配列として取得できるPythonからの挑戦状です。
[ reply ]