Extract string using regex in Python -


i'm struggling bit on how extract (i.e. assign variable) string based on regex. have regex worked out -- tested on regexpal. i'm lost on how implement in python. regex string is:

http://jenkins.mycompany.com/job/[^\s]+ 

what want take string , if there's pattern in there matches regex, put entire "pattern" variable. example, given following string:

there problem http://jenkins.mycompany.com/job/app/4567. should fix this. 

i want extract http://jenkins.mycompany.com/job/app/4567and assign variable. know i'm supposed use re i'm not sure if want re.match or re.search , how want. or pointers appreciated.

import re p = re.compile('http://jenkins.mycompany.com/job/[^\s]+') line = 'there problem http://jenkins.mycompany.com/job/app/4567.   should fix this.' result = p.search(line) print result.group(0) 

output:

http://jenkins.mycompany.com/job/app/4567. 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -