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.match re.search (Python)

import re
print(re.match(r'aaa', 'aaab'))
print(re.match(r'aaa', 'baaa'))
print(re.search(r'aaa', 'aaab'))
print(re.search(r'aaa', 'baaa'))

<re.Match object; span=(0, 3), match='aaa'>
None
<re.Match object; span=(0, 3), match='aaa'>
<re.Match object; span=(1, 4), match='aaa'>

re.matchは先頭からのマッチになります。
こちらの記事が分かりやすい。

match (Ruby)

p 'aaab'.match(/^aaa/)
p 'baaa'.match(/^aaa/)
p 'aaab'.match(/aaa/)
p 'baaa'.match(/aaa/)

#<MatchData "aaa">
nil
#<MatchData "aaa">
#<MatchData "aaa">

先頭からにするかどうかは、正規表現側で定義します。

メモ

  • Python の re.match re.search を学習した
  • 百里を行く者は九十里を半ばとす
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?