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

  • Home
  • SEARCH
  • 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 8035449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:18:48+00:00 2026-06-05T02:18:48+00:00

If I have a string like this (from a Wiki-markup) that I need to

  • 0

If I have a string like this (from a Wiki-markup) that I need to parse in Java:

this link (is [[ inParen ]] and) (this) one is [[ notInParen ]]

I’d like to use regex to extract the texts inside the [[ ]] but not if they are inside parentheses. For example, in the example above it should return:

notInParen

But ignore:

inParen and this

… since they are inside parentheses. I can find the parentheses and the brackets separately no problem:

.*\(.*?\).* and .*?\[\[(.*?\]\].*

…but can’t figure out how to find the [[ ]], look around for parentheses, and ignore. Thanks!

  • 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-05T02:18:52+00:00Added an answer on June 5, 2026 at 2:18 am

    This is a fine regex

    \(.*?\)|\[\[(.*?)]]
    

    Your desired match will be in group 1

    FYI, to make it better perform you can minimize backtracking by replacing the lazy match with a negated character class.

    In Java this becomes

    String ResultString = null;
    try {
        Pattern regex = Pattern.compile("\\(.*?\\)|\\[\\[(.*?)\\]\\]", Pattern.DOTALL | Pattern.MULTILINE);
        Matcher regexMatcher = regex.matcher(subjectString);
        if (regexMatcher.find()) {
            ResultString = regexMatcher.group(1);
        } 
    } catch (PatternSyntaxException ex) {
        // Syntax error in the regular expression
    }
    

    Note that group 1 will be empty for the cases the first part of the alternation did match.

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

Sidebar

Related Questions

I have a string like this: http://www.downlinegoldmine.com/viralmarketing I need to remove http://www. from the
I have a string like this: 2010-01-01 12:30:00 I need that to convert to
how can i read one line from string ??? i have string like this
I am getting JSON string from website. I have data which looks like this
I have strings that I download from the web that look like this: משה
I have string like this 0 0.014E5 and I need it split into a
Need a little help with string formatting... I have a string like this: Bmw
I have string like this: http://someurl.com?someparameter=dhws6sd6cvg and i would like to mach part from
I have a string like this namespace.fun1.fun2.fun3 passed from the client. It's telling the
In Java I have a string like this 0564\n5523\n5445\n8596 and I'd like more or

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.