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 669657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:10:29+00:00 2026-05-14T00:10:29+00:00

I have text that looks like: My name is (Richard) and I cannot do

  • 0

I have text that looks like:

My name is (Richard) and I cannot do
[whatever (Jack) can’t do] and
(Robert) is the same way [unlike
(Betty)] thanks (Jill)

The goal is to search using a regular expression to find all parenthesized names that occur anywhere in the text BUT in-between any brackets.

So in the text above, the result I am looking for is:

  • Richard
  • Robert
  • Jill
  • 1 1 Answer
  • 1 View
  • 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-14T00:10:30+00:00Added an answer on May 14, 2026 at 12:10 am

    You didn’t say what language you’re using, so here’s some Python:

    >>> import re
    >>> REGEX = re.compile(r'(?:[^[(]+|\(([^)]*)\)|\[[^]]*])')
    >>> s="""My name is (Richard) and I cannot do [whatever (Jack) can't do] and (Robert) is the same way [unlike (Betty)] thanks (Jill)"""
    >>> filter(None, REGEX.findall(s))
    

    The output is:

    ['Richard', 'Robert', 'Jill']
    

    One caveat is that this does not work with arbitrary nesting. The only nesting it’s really designed to work with is one level of parens in square brackets as mentioned in the question. Arbitrary nesting can’t be done with just regular expressions. (This is a consequence of the pumping lemma for regular languages.)

    The regex looks for chunks of text without brackets or parens, chunks of text enclosed in parens, and chunks of text enclosed in brackets. Only text in parens (not in square brackets) is captured. Python’s findall finds all matches of the regex in sequence. In some languages you may need to write a loop to repeatedly match. For non-paren matches, findall inserts an empty string in the result list, so the call to filter removes those.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I have @hash that looks like this: [1, {:clid=>1, :nvz=>4, :tip=>IP, :name=>Mark, :record=>some text}]
I have a MySQL table that looks like this: id (int primary) name (text)
I have HTML that looks like this: <form id=kinodForm> <input type=text name=element[5] value=krispy kreme
I have long text containing name that looks like something-something. This long text is
I have a chatlog file that looks like this (name represents screenames and text
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
I have a text file that looks like this. A 102 B 456 C
I have a text file that looks like this: value1 value2 value3 There are
I have a text file that looks a bit like: random text random text,

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.