Extracting text from variable - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Extracting text from variable (/showthread.php?tid=145704) |
Extracting text from variable - moh-san - 2012-11-19 Hi, Bit of a strange question but I hope someone can help me with this. What I have is a variable that's called: this.is.a.test.s54352.test Now the, this.is.a.test part is dynamic and changes all the time also the character count changes. but that's the part I need to have. So I want to strip: this.is.a.test.s54352.test TO this.is.a.test Thank you for looking in to this. moh-san RE: Extracting text from variable - moh-san - 2012-11-19 Found it already, sorry to bother. Code: import re RE: Extracting text from variable - sphere - 2012-11-19 You know that the regular expression '.s' means "any character followed by an s-charachter" and not "dot followed by s"? Anyway, if you just search for any string bevore a given pattern (dot followed by s) you could do it in much other (simpler) ways: Code: string = "this.is.a.test.s54352.test" And there are dozens more using regular expressions right. It absolutely depends on the strings to search in, patterns to find with and finally the substring you look for Maybe next time give more than one example or describe the scheme... regards, sphere |