Match part of string until it reaches end of string (python regex)

If I have a large line with several lines, and I want to combine part of the line only with the end of this line, what is the best way to do this?

So, for example, I have something like this, and I want it to stop matching when it reaches a new line character.

r"(?P<name>[A-Za-z\s.]+)"

I saw this in the previous answer :

$ - indicates coincidence with the end of the line or the end of the line, if multi-line is allowed.

My question is how do you "enable multiline," as the author of this answer claims?

+5
source share
3 answers

Just use

r"(?P<name>[A-Za-z\t .]+)"

ASCII, , . , , - ( \s, - , ).

+8

, re.MULTILINE re.compile(). , , : + , , , , ($ ).

:

  • , , (\s), .
  • +?, ( "" ) +, , , .
  • , ( text.split('\n').
+2

All Articles