Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:32:05+00:00 2026-05-30T14:32:05+00:00

my first time here, title is bad i know :) Well, this is what

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:32:06+00:00Added an answer on May 30, 2026 at 2:32 pm

    Sure, you use optional groups:

    >>> patt = re.compile("foo (?P<name>[0-9]+)?")
    >>> patt.search("blah foo 999 bar").groupdict()
    {'name': '999'}
    >>> patt.search("blah foo bar").groupdict()
    {'name': None}
    

    Your example, somewhat simplified for length:

    prefix (?P<optional1>\[.*?\])? same-words \((?P<date>.*?)\)(?P<optional2> \[.*?\])?: \((?P<g3>.*?)\) END
    

    Then once you have a match, you can do:

    d = patt.search(str).groupdict()
    g2 = d["optional1"] if d["optional1"] is not None else d["optional2"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time here so I hope I post this question at
this is my first time posting here, I have a question which I have
Here's the scenario: if this is a user's first time logging into my web
Sorry, this's my first time to ask a question here. So, I don't have
first time posting here. I'm using a loop to create 3 buttons, but my
First time poster here. A quick question about setting up a loop here. I
So here I am, first time windows developer (done java swing, iphone, flash/flex) and
first time SO user :) I know that I can format a number like
This is really weird. Its my first time with using the mustache library and
Following this post which I posted some time ago, I now get the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.