0
1

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.

Pythonの文字列検索で、対象の左の文字を入手する方法

Posted at

eva="~~~○gouki~~~" ←○の中に毎回ランダムな数字が入るとして、その数字を入手する方法

対象の右は探しやすいけど、左は情報が無かったので置いときます。
正規表現を学ぶと理解が進むぞ!

search&getleft
import re

# ○には毎回ランダムな数字が入る処理
eva = "くぁwせdrf○goukitgyふじこlp;@:「」"

# 正規表現で探したい文字列を記述する
evasearch = r'.gouki(.*)'

evacode = re.search(evasearch,eva)
evanumbers = evacode.group(0)
evanumber = evanumbers[0]

print(evanumber)
0
1
4

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?