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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:42:52+00:00 2026-06-17T11:42:52+00:00

First of all, let me please clarify that I know absolutely nothing about regular

  • 0

First of all, let me please clarify that I know absolutely nothing about regular expressions, but I need to write a “Tagger Script” for MusicBrainz Picard so that it doesn’t mess with the way I format certain aspects of my tracks’ titles.

Here’s what I need to do:
– Find all sub-strings inside parenthesis
– Then, for those matches that meet a given criteria and those matches only, change the parentheses to brackets

For example, consider this string:
DJ Fresh – Louder (Sian Evans) (Flux Pavilion & Doctor P Remix)

It needs to be changed like so:
DJ Fresh – Louder (Sian Evans) [Flux Pavilion & Doctor P Remix]

The condition is that if the string within the parentheses contains the sub-string “dj” or “mix” or “version” or “inch”, etc… then the parentheses surrounding it need to be changed to brackets.

So, the question is:
Is it possible to create a single regex expression that can perform this operation?

Thank you very much in advance.

  • 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-06-17T11:42:53+00:00Added an answer on June 17, 2026 at 11:42 am

    Assuming there are no nested brackets, you can use the following regex to search for the text:

    (?i)\((?=[^()]*(?:dj|mix|version|inch))([^()]+)\)
    

    Note that the regex is case-insensitive, due to (?i) in front – make it case-sensitive by removing it.

    Check the syntax of your language to see if you can use r prefix, e.g. r'literal_string', to specify literal string.

    And use the following as replacement:

    [$1]
    

    You can include more keywords by adding keywords to (?:dj|mix|version|inch) part, each keyword separated by |. If the keyword contains (, ), [, ], |, ., +, ?, *, ^, $, \, {, } you need to escape them (I’m 99% sure the list is exhaustive). An easier way to think about it is: if the keyword only contains space and alphanumeric (but note that the number of spaces is strict), you can add them into the regex without causing side-effect.


    Dissecting the regex:

    • (?i): Case-insensitive mode

    • \(: ( is special character in regex, need to escape it by prepending \.

    • (?=[^()]*(?:dj|mix|version|inch)): Positive look-ahead (?=pattern):

      • [^()]*: I need to check that the text is within bracket, not outside or in some other bracket, so I use a negated character class [^characters] to avoid matching () and spill outside the current bracket. The assumption I made also comes into play a bit here.

      • (?:dj|mix|version|inch): A list of keywords, in a non-capturing group (?:pattern). | means alternation.

    • ([^()]+): The assumption about no nested bracket makes it easier to match all the characters inside the bracket. The text is captured for later replacement, since (pattern) is capturing group, as opposed to (?:pattern).

    • \): ) is special character in regex, need to escape it by prepending \.

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

Sidebar

Related Questions

first of all please let me say that I am quite new to objective
First of all let me tell you that i have read the following questions
First of all, let me say that I am not a professional coder -
First of all, apologize because I have seen some posts about this, but I
First, let me try to clarify that what I mean by control flow is
First of all let me just note that i'm a newbie in the field.
Hi there First of all just let me say that I'm new in Python
First time posting, please let me know if this question has already been answered!
just a quick question. First of all, let me verify that I have the
First of all I have to apologize for my poor English, Please let me

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.