はじめに
移植やってます
re.finditer (Python)
import re
text = "He was carefully disguised but captured quickly by police."
for m in re.finditer(r"\w+ly", text):
print('%02d-%02d: %s' % (m.start(), m.end(), m.group(0)))
# 07-16: carefully
# 40-47: quickly
公式ドキュメントより、こちらの記事のほうが分かりやすい。
scan (Ruby)
text = "He was carefully disguised but captured quickly by police."
puts text.scan(/\w+ly/).map{ "#{text.index(_1).to_s.rjust(2, '0')}-#{(text.index(_1) + _1.size).to_s.rjust(2, '0')}: #{_1}" }
# 07-16: carefully
# 40-47: quickly
String#scan
+String#index
で行けそう。
メモ
- Python の re.finditer を学習した
- 道のりは遠そう