could any one show me how i can use variable url inside Python a regular expression search?Url is the variable passed to the function that holds the code below. I tried the following but keep getting error.Hope some help me fix this error.Thanks in advance. sample str and url value:
str='.......href="http://somewebsite:8080/hls/1.m3u8?session=34534525".....'
url='http://somewebsite:8080/hls/1.m3u8?session='
python code:
foundValue= re.search('+url+(.*)"', str)
print 'foundValue:'
print foundValue.group(1);
error on xbmc logs:
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<--
Guess you wanted this:
foundValue= re.search(re.escape(url)+r'(.*?)"', str1)
Also don't use str
as it is in-built.