Hướng dẫn python regex ignore newline

I am trying to replace all matching occurrences with title cases using the following script. When there is a newline character between filter words [in this case 'ABC' and 'DEF'] that line doesn't get replaced as intended.

How can I ignore the newline character in this case?

Edit: I don't want to strip all newline characters entirely from the string, but only strip those between the filter words.

Edit2: I edited the text and script to better reflect on the issue I am experiencing. If I include flags=re.DOTALL argument, it will give me:

  mmm    = "Hello Hello Hello Hello Hello Hello
              Hello Hello Hello Hello",
  Bbb   = "Bbb",

whereas the output I want is [notice that bbb is not capitalized]:

  mmm    = "Hello Hello Hello Hello Hello Hello
              Hello Hello Hello Hello",
  bbb   = "bbb",

The following is the script I am using.

test_string = '''
  mmm    = "hello hello hello hello hello hello
              hello hello hello hello",
  bbb   = "bbb",
'''

rex = r'[?

Chủ Đề