Removing a certain part of a string in python -



Removing a certain part of a string in python -

"submitted 1 year ago bagelpirate /r/books"

basically i'm learning web scraping , pulled info html of reddit page. need "bagelpirate" out of string. there way in python?

given starting string:

s = "submitted 1 year ago bagelpirate /r/books"

you (finding position of preceding , next substrings):

name = s[s.index(' ')+4:s.index(' /r/books')]

or utilize regular expression:

import re name = re.search(' (.+) /r/books', s).group(1)

that means, 'find "by (something) /r/books" in string , give me part indicated parentheses'.

it kind of depends format strings going in.

python

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -