2021-12-09

Tech Programing

程式人小天地

Issue with regex search python

1 min read


My string is:

test_string = "@@@__slug1^^__firstname [email protected]@@^^^ @@@__slug2^^__firstname1 [email protected]@@^^^"

I am trying to separate slug and lastname in a list my output will be like.

slug_list = [slug1,slug2]
name_list=[firstname lastname,firstname1 lastname1]

I try to first search all the slug my code for the same is.

import re
test_string = "@@@__slug1^^__firstname [email protected]@@^^^ @@@__deletepurpose^^__Delete [email protected]@@^^^"
pattern = "@@@__|(''*?)|^^"
substring = re.search(pattern, test_string).group(1)
print(substring)

But it is giving me error.

AttributeError: 'NoneType' object has no attribute 'group'  



Source link

資料來源:Stackoverflow

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *