Capturing text after a specific character in a python string

I am new to python and I am trying to determine how regular expressions work. I would like to capture everything after GT in this line:

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

thanks for the help!

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

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

+4
source share
2 answers

Use the following:

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

Output (contains line break according to presence \n):

\s*)(.)
", notes)
+2
source

in the example below, every thing is caught after @

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

Source: https://habr.com/ru/post/1681557/


All Articles