my first time here, title is bad i know 🙂
Well, this is what i’m trying to do
Input possibility 1: SOMETHING BLAH always same words here (here comes date/time text, called group 1) [group 2 text]: (group 3 text) END
Input 2: SOMETHING BLAH [group 2 text] always same words here (here comes date/time text, called group 1): (group 3 text) END
group2 can appear before or after
Now, using python and module re, is it possible to match either of these inputs using only 1 regex?
Example (Obviously, something like this is not possible as it contains same name groups):
"SOMETHING BLAH (always same words here \((?P<group1>.{1,40})\) \[(?P<group2>.*?)\]: \((?P<group3>.*?)\)|\[(?P<group2>.*?)\] always same words here \((?P<group1>.{1,40})\): (group 3 text) ) END", re.DOTALL
It’s just an exmp for what im trying to do
Sure, you use optional groups:
Your example, somewhat simplified for length:
Then once you have a match, you can do: