質問編集履歴

1

修正依頼を受けて、データを修正

2016/10/05 05:57

投稿

nnahito
nnahito

スコア2004

test CHANGED
File without changes
test CHANGED
@@ -125,3 +125,65 @@
125
125
  Python 2.7.10
126
126
 
127
127
  MacOS X 10.10.5(Yosemite)
128
+
129
+
130
+
131
+
132
+
133
+ # 修正依頼からの修正
134
+
135
+ コード
136
+
137
+ ```lang-python
138
+
139
+ #!/usr/bin/env python
140
+
141
+ # -*- coding: utf8 -*-
142
+
143
+
144
+
145
+ import re
146
+
147
+
148
+
149
+ text = u'hogehoge http://www.example.com/ mugemuge'
150
+
151
+
152
+
153
+
154
+
155
+ # URLを抜き出し
156
+
157
+ urls = re.search(u'http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?', text)
158
+
159
+
160
+
161
+ for i in urls:
162
+
163
+ print i
164
+
165
+ ```
166
+
167
+
168
+
169
+ エラー
170
+
171
+ ```
172
+
173
+ Traceback (most recent call last):
174
+
175
+ File "test.py", line 10, in <module>
176
+
177
+ urls = re.search(u'http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?', text)
178
+
179
+ File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 146, in search
180
+
181
+ return _compile(pattern, flags).search(string)
182
+
183
+ File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 251, in _compile
184
+
185
+ raise error, v # invalid expression
186
+
187
+ sre_constants.error: bad character range
188
+
189
+ ```