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 5 years have passed since last update.

備忘録 正規表現 文字列の中に区切りたい文字が複数ある場合

Posted at

正規表現での処理

・ 最短一致
・ 最長一致

【例文】 
String = "フリースローチャレンジ_ hogeさん _1回目"

上記文字列に対して
① フリースローチャレンジのみを抽出したい(最初のアンダーバーより前を抽出)
② 何回目かを抽出したい(最後のアンダーバー以降を抽出)

① -> re.search("(.?)(?=_)", String)[0] → フリースローチャレンジ が抽出
② -> re.search("([^_]
$)", x)[0] → 1回目 が抽出される

0
0
0

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?