Re: Module re, extract on string match

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Timothy Grant

    Re: Module re, extract on string match

    On Mon, Aug 4, 2008 at 4:54 PM, Sriram Rajan <sriramrajan@ac m.orgwrote:
    I am wondering if I can use re.search to extract from a particular
    location in a string.
    Example:
    string1='/Users/sriram/folder1/folder2/folder3/folder4/folder5/file'
    re.search ('folder3,strin g1)
    >
    <Extract /folder3/folder4/folder5/file>
    >
    Thanks,
    >
    Sriram
    Something like below?

    Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
    [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
    Type "help", "copyright" , "credits" or "license" for more information.
    >>import re
    >>s = '/Users/sriram/folder1/folder2/folder3/folder4/folder5/file'
    >>y = re.search('fold er3.*', s)
    >>y.group()
    'folder3/folder4/folder5/file'
    >>>

    --
    Stand Fast,
    tjg. [Timothy Grant]
Working...