0

svn-backup-test,2014/09/24/18/Rev1223/FullSvnCheckout.tgz

from the following string I need to fetch Rev1233. So i was wondering if we can have any regexpression to do that. I like to do following string.search ("Rev" uptill next /)

so far I split this using split array s1,s2,s3,s4,s5 = string ("/",4)

3 Answers 3

2

You don't need a regex to do this. It is as simple as:

 str = 'svn-backup-test,2014/09/24/18/Rev1223/FullSvnCheckout.tgz'
 str.split('/')[-2]
Sign up to request clarification or add additional context in comments.

Comments

0

Here is a quick python example

>>> impot re
>>> s = 'svn-backup-test,2014/09/24/18/Rev1223/FullSvnCheckout.tgz'
>>> p = re.compile('.*/(Rev\d+)/.*')
>>> p.match(s).groups()[0]
'Rev1223'

Comments

0

Find second part from the end using regex, if preferred:

/(Rev\d+)/[^/]+$

http://regex101.com/r/cC6fO3/1

>>> import re
>>> m = re.search('/(Rev\d+)/[^/]+$', 'svn-backup-test,2014/09/24/18/Rev1223/FullSvnCheckout.tgz')
>>> m.groups()[0]
'Rev1223'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.