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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:46:43+00:00 2026-06-17T21:46:43+00:00

program A { int x = 10; tuple date { int day; int month;

  • 0
program A {
   int x = 10;
   tuple date {
            int day;
            int month;
            int year;
   }
}

function B {
    int y = 20;
    ...
}

process C {
    more code;
}

I’d like to extract whatever is inside the outer curly braces for program, function and process. In terms of the output, I want to see three matches:

       int x = 10;
       tuple date {
                int day;
                int month;
                int year;
       } //first match

       int y = 20;
       ... //second match

       more code; //third match

I’ve achieved this using Javascript. The regular expression I use is /(program|function|process).*?{(.*?)}\n+(program|function|process)/m, which works as demonstrated by Rubular.

However, when I use the same expression in Java it wouldn’t work any more. It only returns the first match. I have a vague memory that the consumed text in a previous match will not be matched again. In my case, the keywords program and function have been consumed in the first match, resulting in no further matches. Is there a way in Java to match the consumed text?

Edit: the Java code is posted below as requested.

public class Test {
    public static void main(String[] args) throws IOException {
        String input = FileUtils.readFileToString(new File("input.txt"));
        Pattern p = Pattern.compile("(program|function|process)[^\\{]*?\\{(.*?)\\}\\s*(program|function|process)", Pattern.DOTALL);
        Matcher m = p.matcher(input);
        while(m.find()) {
            System.out.println(m.group(2));
        }
    }
}
  • 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-17T21:46:44+00:00Added an answer on June 17, 2026 at 9:46 pm

    You can solve your problem by using lookarounds..so your regex would be

    (?<=program|function|process)[^{]*\\{(.*?)\\}\\s*(?=program|function|process|$) 
    

    Group 1 would have your data..

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

Sidebar

Related Questions

program A { int x = 10; tuple date { int day; int month;
I have a program structure like following : int firstFunction(unsigned char *firstValue, int s,
Let's say I have this line of code in a program: int * number=0;
Consider the following C program: int i = 0; int post_increment_i() { return i++;
This is my program: int main(int argc, char *argv[]){ if(argc != 2){ printf(Uso: ./server
Consider this program int main() { float f = 11.22; double d = 44.55;
I have this C++ program: int box[9][9]; box = { {solution[0][0],solution[0][1],solution[0][2],solution[1][0],solution[1][1],solution[1][2],solution[2][0],solution[2][1],solution[2][2]}, {solution[0][3],solution[0][4],solution[0][5],solution[1][3],solution[1][4],solution[1][5],solution[2][3],solution[2][4],solution[2][5]}, {solution[0][6],solution[0][7],solution[0][8],solution[1][6],solution[1][7],solution[1][8],solution[2][6],solution[2][7],solution[2][8]}, {solution[3][0],solution[3][1],solution[3][2],solution[4][0],solution[4][1],solution[4][2],solution[5][0],solution[5][1],solution[5][2]},
I don't understand the output of this program: int arr[]={1,7,4,2,5,8}; int x=(&(arr[arr[1]-arr[4]])-arr); printf(%d ,x);
Consider the following example program: next :: Int -> Int next i | 0
class Program { internal delegate int CallBack(int i); static void Main(string[] args) { CallBack

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.