回答編集履歴

3

訂正

2018/08/21 08:34

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -12,7 +12,9 @@
12
12
 
13
13
 
14
14
 
15
- ご提示の正規表現は、『 \ あるいは . あるいは * 』を表現してしまっています。
15
+ ご提示の正規表現は、~~『 \ あるいは . あるいは * 』を表現してしまっています。~~
16
+
17
+ **訂正: **『 . あるいは * 』を表現してしまっています。
16
18
 
17
19
 
18
20
 

2

追記

2018/08/21 08:34

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -13,3 +13,47 @@
13
13
 
14
14
 
15
15
  ご提示の正規表現は、『 \ あるいは . あるいは * 』を表現してしまっています。
16
+
17
+
18
+
19
+ もしくは
20
+
21
+ ---
22
+
23
+ [文字列のメソッド](https://docs.python.jp/3/library/stdtypes.html#string-methods)をうまく利用する方法が一つ。
24
+
25
+ ```Python
26
+
27
+ >>> ''.join(time.split('.')[:-1])
28
+
29
+ '17:26:30'
30
+
31
+ ```
32
+
33
+
34
+
35
+ [datetime](https://docs.python.jp/3/library/datetime.html)モジュールを利用しても良いでしょう。
36
+
37
+ ```Python
38
+
39
+ >>> import datetime as dt
40
+
41
+ >>>
42
+
43
+ >>> t = dt.datetime.strptime(time, '%H:%M:%S.%f')
44
+
45
+ >>> print(t)
46
+
47
+ 1900-01-01 17:26:30.123456
48
+
49
+ >>>
50
+
51
+ >>> t.strftime('%H:%M:%S')
52
+
53
+ '17:26:30'
54
+
55
+ ```
56
+
57
+
58
+
59
+ 参考: [Python 標準ライブラリ » datetime » strftime() と strptime() の振る舞い](https://docs.python.jp/3/library/datetime.html#strftime-strptime-behavior)

1

追記

2018/08/21 08:32

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -9,3 +9,7 @@
9
9
  'HH:MM:SS'
10
10
 
11
11
  ```
12
+
13
+
14
+
15
+ ご提示の正規表現は、『 \ あるいは . あるいは * 』を表現してしまっています。