Python Forum

Full Version: Regular expression: match pattern at the end only
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Try this perhaps r"\([^()]*\)$"
Works!
Thanks.
^() means doesn't include fragments that contain both symbols: '(' and ')', isn't it ?
[^()] means any character different from ( and )