2017-05-19 7 views

答えて

2

ここ©

import re 

text = "This is all test and try things that's going on bro Copyright© Bro Code Bro" 

print(re.findall(".{4}©.{4}", text)) 

出力の前と後の4つの文字を取得するために正規表現のみソリューションです:彼は私が抽出しようとしている `言っ

['ight© Bro'] 
+0

ありがとう、それは期待どおりに正確に働いた。 – Pandsh

+0

@Pandsh喜んで助けることができました。 – moritzg

0

を取得するために、文字列全体をしたくありません!

使用する検索あなたは

symbol=re.search(r"(?<=©).+$",html).start() 

を好きなように、この場合には、上記の行は、あなたの試合の指標を与え、その後、インデックスとスライス/サイコロの文字列を取得するための63

使用

html[symbol:symbol+4] for post and html[symbol-4:symbol] for pre. 
0

:印刷、ほんの数文字)このようにそれをやってみ

import re 
    html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" 
    if "©" in html: 
     symbol=re.findall(r"(?<=©).+$",html,re.M) 
     print(symbol[0][0:100]) 
1
html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" 
html = html.split("©") 

print(html[0][-4:]) 
print(html[1][:4]) 

出力:

ight 
Bro 
0

問題を解決するには、関数split()でビルドされたPythonを使用してください。

html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split('©')

+0

あなたの解決策はこれを提供していません。 – moritzg

関連する問題