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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:01:23+00:00 2026-05-11T10:01:23+00:00

in this text : text text text [[st: aaa bbb ccc ddd eee fff]]

  • 0

in this text :

 text text text [[st: aaa bbb ccc ddd eee fff]] text text text text [[st: ggg hhh iii jjj kkk lll mmm nnn]] text text text 

I’m trying to get the text between the [[st: and that ends with ]]

My program should output:

 aaa bbb ccc ddd eee fff  (first match) ggg hhh iii jjj kkk \n lll mmm nnn(second match) 

But I can only get it to return the first [[st: and the last ]], so there is just one match instead of two. Any ideas?

Here’s my code:

package com.s2i.egc.test;  import java.util.regex.Matcher; import java.util.regex.Pattern;  public class TestRegex {      /**      * @param args      */     public static void main(String[] args) {          String bodyText = 'text text text [[st: aaa bbb ccc ddd eee fff]] text text text text [[st: ggg hhh iii jjj kkk\n lll mmm nnn]] text text text';          String currentPattern = '\\[\\[st:.*\\]\\]';          Pattern myPattern = Pattern.compile(currentPattern, Pattern.DOTALL);          Matcher myMatcher = myPattern.matcher(bodyText);          int i = 1;          while (myMatcher.find()) {           String match = bodyText.substring(myMatcher.start() + 5, myMatcher.end() - 3);           System.out.println(match + ' (match #' + i + ')');           i++;         }                                  }  } 
  • 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. 2026-05-11T10:01:23+00:00Added an answer on May 11, 2026 at 10:01 am

    The quantifier * (0 or more) is greedy by default, so it matches to the second ]].

    Try changing to a reluctant pattern match:

    String currentPattern = '\\[\\[st:.*?\\]\\]'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can not display HTML result in TextArea/TextBox control. But… May 11, 2026 at 12:08 pm
  • added an answer This looks like a case for generics to me. Your… May 11, 2026 at 12:08 pm
  • added an answer The key piece of information in the question is this:… May 11, 2026 at 12:08 pm

Related Questions

For example, in this text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
I'm trying to read the contents of a text file, in this case a
In the context of this question link text is possible from a Controller that
i've got this tables in my database. alt text http://img166.imageshack.us/img166/3133/testdbschemafy5.png With Entity Framework i
I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
Every so often when I'm debugging, I get this message in nice brown text
In a project we have text files looking like this: mv A, R3 mv
In a text file, there is a string I don't like this. However, when
I am using a custom validator to compare value in two text box. This
In other words, a block of code like this: (setq initial-major-mode (lambda () (text-mode)

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.