回答編集履歴
1
追記
answer
CHANGED
@@ -14,4 +14,30 @@
|
|
14
14
|
print(group)
|
15
15
|
```
|
16
16
|
|
17
|
-
[Wandbox](https://wandbox.org/permlink/CZEw2drZo5gS86Aa)
|
17
|
+
[Wandbox](https://wandbox.org/permlink/CZEw2drZo5gS86Aa)
|
18
|
+
|
19
|
+
あるいはこんなのも。
|
20
|
+
```Python
|
21
|
+
import re
|
22
|
+
|
23
|
+
path = 'C:/Users/user_name/フォルダ1/フォルダ2/2014-2017/2017/テキスト(1500番)\10番\テキストタイトル.txt'
|
24
|
+
|
25
|
+
result = re.split(
|
26
|
+
r'[/(())\]+',
|
27
|
+
path
|
28
|
+
)[-4:]
|
29
|
+
|
30
|
+
for elem in result:
|
31
|
+
print(elem)
|
32
|
+
```
|
33
|
+
|
34
|
+
[Wandbox](https://wandbox.org/permlink/skSehswmTWvGrCqJ)
|
35
|
+
|
36
|
+
---
|
37
|
+
この場合scanf系の関数があればそれが一番楽なのですが、標準では用意していないようです。
|
38
|
+
> **scanf() や sscanf() と同等なものはありますか?**
|
39
|
+
> そのようなものはありません。
|
40
|
+
> [中略]
|
41
|
+
> もっと複雑な入力解析をしたいなら、C の sscanf() よりも正規表現の方が便利ですし、この処理に向いています。
|
42
|
+
|
43
|
+
引用元: [Python よくある質問 » プログラミング FAQ](https://docs.python.jp/3/faq/programming.html#is-there-a-scanf-or-sscanf-equivalent)
|