Ashley
Ashley

Reputation: 413

Capturing text after a certain character in a string python

I am new to python and i am trying to lean how regexs work. I would like to capture everything after the GT in this string:

string = re.search(r"(GT\s*)(.)\n", notes)

thanks for the help!

Edit: I would like the output to look like this:

\s*)(.)\n", notes)

Upvotes: 5

Views: 6320

Answers (2)

RomanPerekhrest
RomanPerekhrest

Reputation: 92894

Use the following:

s = 'string = re.search(r"(GT\s*)(.)\n", notes)'
m = re.search(r'GT(.*)', s, re.DOTALL)
print(m.group(1))

The output (contains line-break according to \n presence):

\s*)(.)
", notes)

Upvotes: 3

Kallz
Kallz

Reputation: 3523

in below example every thing catch after @

 >>>import re
 >>>re.findall(r'@(\w+)', '@hi there @kallz @!')
 >>>['hi', 'kallz']

Upvotes: 0

Related Questions