回答編集履歴
1
Update
test
CHANGED
@@ -1,30 +1,24 @@
|
|
1
|
-
> スライスした時と同じように抽出したいです。
|
2
1
|
```python
|
3
|
-
import locale
|
4
2
|
import re
|
5
3
|
|
6
4
|
#ファイルパステキスト
|
7
5
|
path = r"C:\Users\test\Desktop\test.txt"
|
8
6
|
|
9
|
-
#ファイル読み込む
|
10
7
|
with open(path, "r", encoding="utf-8") as f:
|
11
|
-
|
8
|
+
text = f.read()
|
12
9
|
|
13
|
-
#新しいリスト作成して特定の文字を置換
|
14
|
-
|
10
|
+
text = re.sub(r'[ ·\ufeff]', '', text)
|
11
|
+
block = re.findall(
|
12
|
+
r'^\d+年\d+月\d+日$(?:(?!^\d+年\d+月\d+日$).)+?Enterキーで投稿します',
|
13
|
+
text, re.DOTALL|re.MULTILINE)
|
15
14
|
|
16
|
-
#スライスして投稿情報取得
|
17
|
-
|
15
|
+
New_list = [b.split('\n') for b in block]
|
16
|
+
search_words = ['#python', 'Python簡単', '#programin']
|
18
17
|
|
19
|
-
|
18
|
+
for l in New_list:
|
20
|
-
search_words = ['#python', 'Python簡単', '#programin']
|
21
|
-
i
|
19
|
+
if all(w in l for w in search_words):
|
22
|
-
|
23
|
-
if is_includes:
|
24
|
-
print([i if (i in search_words) else '' for i in s])
|
25
|
-
else:
|
26
|
-
print(
|
20
|
+
print(l)
|
27
21
|
|
28
22
|
#
|
29
|
-
['', '', '', '', '', '#python', '', '#programin', '', '', '', 'Python簡単', '', '', '']
|
23
|
+
['2022年3月1日', '', 'テスト投稿', '', 'TEST', '#python', '#code', '#programin', 'プログラミング', '簡単', 'コーディング', 'Python簡単', 'pythonできること', '', 'Enterキーで投稿します']
|
30
24
|
```
|