Python Forum
problem in matching in regex
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in matching in regex
#2
The regex is not at all right for this task,as you use regex101 on right side it will explain what the regex is doing.
import re

test_str = "These books are good.\nThe weather is nice.\nwhere are you going?\nthe car is green"
pattern = r'^The\s.*'
matches = re.finditer(pattern, test_str, re.MULTILINE)
for match in matches:
    print(match.group()) 
Output:
The weather is nice.
If also want lowercase add re.MULTILINE | re.IGNORECASE
Output:
The weather is nice. the car is green
akbarza likes this post
Reply


Messages In This Thread
problem in matching in regex - by akbarza - Nov-21-2023, 08:15 AM
RE: problem in matching in regex - by snippsat - Nov-21-2023, 09:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with code / audio is playing randomly, not matching csv requirements Daniel_kcr 2 775 Sep-07-2023, 05:09 PM
Last Post: deanhystad
  Problem in Regex Expression shantanu97 2 1,850 Sep-28-2021, 03:40 AM
Last Post: shantanu97
  Matching Regex in Python from Excelfile and inserting into database Shuzo 0 1,715 May-14-2020, 06:53 PM
Last Post: Shuzo
  Automate the boring stuff: regex not matching DJ_Qu 7 3,984 Apr-27-2019, 07:03 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020