0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

移植やってます

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 を学習した
  • 道のりは遠そう
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?