Reg Ex help

Aaron Barclay aaronb at mrxfx.com
Thu May 11 19:58:24 CEST 2006


Hi don,

there may well be a better way then regex, although I find them usefull 
and use them a lot.

The way they work would be dependant on knowing some things. For 
example, if the dir you are after is always 4
deep in the structure you could try something like...

path =  
'/main/parallel_branch_1/release_branch_1.0/dbg_for_python/CHECKEDOUT

from /main/parallel_branch_1/release_branch_1.0/4'

p = re.compile('/\S*/\S*/\S*/(\S*)/')
m = re.search(p, path)
.
if m:
    print m.group(1)
   

This is a good reference...
http://www.amk.ca/python/howto/regex/

Hope that helps,
aaron.

don wrote:

>I have a string  from a clearcase cleartool ls command.
>
>/main/parallel_branch_1/release_branch_1.0/dbg_for_python/CHECKEDOUT
>from /main/parallel_branch_1/release_branch_1.0/4
>
>I want to write a regex that gives me the branch the file was
>checkedout on ,in this case - 'dbg_for_python'
>
>Also if there is a better way than using regex, please let me know.
>
>Thanks in advance,
>Don
>
>  
>




More information about the Python-list mailing list