私は正規表現を作成してブローカデータ内のオプションシンボルを見つけようとしています。 Wikipediaあたり形式は:基礎となる株式やETFのPython Regex for Equity Optionが一致しません
- ルートシンボルは、フォーマットの6桁が
- オプションタイプをYYMMDD、
- 賞味期限6つの文字にスペースを埋め、P又はCのいずれかで、 :用の8桁
に0との価格×1000、フロントパディングとして、入れたり
option_regex = re.compile(r'''(
(\w{1,6}) # beginning ticker, 1 to 6 word characters
(\s)? # optional separator
(\d{6}) # 6 digits for yymmdd
([cp]) # C or P for call or put
(\d{8}) # 8 digits for strike price
)''', re.VERBOSE | re.IGNORECASE)
しかし、私はそれをテストするとき、私はエラーを取得:
import re
option_regex = re.compile(r'''(
(\w{1,6}) # beginning ticker, 1 to 6 word characters
(\s)? # optional separator
(\d{6}) # 6 digits for yymmdd
([cp]) # C or P for call or put
(\d{8}) # 8 digits for strike price
)''', re.VERBOSE | re.IGNORECASE)
result = option_regex.search('AAPL 170818C00155000')
result.group()
Traceback (most recent call last):
File "<ipython-input-4-0273c989d990>", line 1, in <module>
result.group()
AttributeError: 'NoneType' object has no attribute 'group'
わからないが、あなたの正規表現は、唯一のティッカーシンボルの後にスペースを可能にし、あなたの例の文字列を持っています二。 – brittenb
ありがとう、それを逃した。 –