谁能告诉我如何在 Python 中使用变量 url 进行正则表达式搜索?Url 是传递给保存下面代码的函数的变量。我尝试了以下但不断收到错误。希望有人帮助我解决此错误。在此先感谢。示例 str 和 url 值:
str='.......href="http://somewebsite:8080/hls/1.m3u8?session=34534525".....'
url='http://somewebsite:8080/hls/1.m3u8?session='
蟒蛇代码:
foundValue= re.search('+url+(.*)"', str)
print 'foundValue:'
print foundValue.group(1);
xbmc 日志上的错误:
ERROR: EXCEPTION Thrown (PythonToCppException) :
-->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'sre_constants.error'>
Error Contents: nothing to repeat
Traceback (most recent call last):
File "F:\......\addon.py", line 281, in <module>
play_video(url)
File "F:\.......\addon.py", line 160, in play_video
foundValue = re.search('+url+(.*)"', str)
File "F:\.....\XBMC\system\python\Lib\re.py", line 142, in search
return _compile(pattern, flags).search(string)
File "F:\....\XBMC\system\python\Lib\re.py", line 242, in _compile
raise error, v # invalid expression
error: nothing to repeat
-->End of Python script error report<--