On Sep 8, 2:15 pm, MRAB <pyt...@mrabarnett.plus.com> wrote: > Martin wrote: > > Hi, > > > I need to extract a string after a matching a regular expression. For > > example I have the string... > > > s = "FTPHOST: e4ftl01u.ecs.nasa.gov" > > > and once I match "FTPHOST" I would like to extract > > "e4ftl01u.ecs.nasa.gov". I am not sure as to the best approach to the > > problem, I had been trying to match the string using something like > > this: > > > m = re.findall(r"FTPHOST", s) > > > But I couldn't then work out how to return the "e4ftl01u.ecs.nasa.gov" > > part. Perhaps I need to find the string and then split it? I had some > > help with a similar problem, but now I don't seem to be able to > > transfer that to this problem! > > > Thanks in advance for the help, > > m = re.search(r"FTPHOST: (.*)", s) > print m.group(1)
so the .* means to match everything after the regex? That doesn't help in this case as the string is placed amongst others for example. MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', -- http://mail.python.org/mailman/listinfo/python-list