Python Forum
Regular expression: match pattern at the end only
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular expression: match pattern at the end only
#1
Hello,

Here are two strings:

Control Engineering – MATLAB Exercises (Advanced Textbooks in Control and Signal Processing)
Control Engineering – (AAAA) MATLAB Exercises (Advanced Textbooks in Control and Signal Processing)

1st string has one part in parentheses (at the end), 2nd string has two parts in parentheses: in the middle and at the end.

How math only trailing part in 2nd string using regex?
The pattern ' \(.+\)' matches like this:
Control Engineering – (AAAA) MATLAB Exercises (Advanced Textbooks in Control and Signal Processing)
Thanks.
Reply
#2
Try this perhaps r"\([^()]*\)$"
Reply
#3
Works!
Thanks.
^() means doesn't include fragments that contain both symbols: '(' and ')', isn't it ?
Reply
#4
[^()] means any character different from ( and )
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  data validation with specific regular expression shaheen07 0 325 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Regex pattern match WJSwan 2 1,243 Feb-07-2023, 04:52 AM
Last Post: WJSwan
  Regular Expression search to comment lines of code Gman2233 5 1,659 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,660 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 1,916 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,164 Mar-09-2022, 10:34 PM
Last Post: snippsat
  I need to copy all the directories that do not match the pattern tester_V 7 2,408 Feb-04-2022, 06:26 PM
Last Post: tester_V
  regular expression question Skaperen 4 2,475 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  How can I find all combinations with a regular expression? AlekseyPython 0 1,667 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  Python Regular expression, small sample works but not on file Acernz 5 2,920 Jun-09-2021, 08:27 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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