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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:16:11+00:00 2026-06-17T21:16:11+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 curly braces following A, B, C. I write the following code, but it does not work.

public class Test {
    public static void main(String[] args) throws IOException {
        String input = FileUtils.readFileToString(new File("input.txt"));
        System.out.println(input);
        Pattern p = Pattern.compile("(program|function|process).*?\\{(.*?)\\}\n+(program|function|process)", Pattern.DOTALL);
        Matcher m = p.matcher(input);
        while(m.find()) {
            System.out.println(m.group(1));
        }
    }
}

Anyone could tell what I didn’t get right?

I’ve tested the regular expression in Javascript and it worked. See here.

  • 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:16:12+00:00Added an answer on June 17, 2026 at 9:16 pm

    try

        Pattern p = Pattern.compile("\\{(.*?)\\}(?!\\s*\\})\\s*", Pattern.DOTALL);
        Matcher m = p.matcher(input);
        while (m.find()) {
            System.out.println(m.group(1));
        }
    

    output

       int x = 10;
       tuple date {
                int day;
                int month;
                int year;
       }
    
    
        int y = 20;
        ...
    
    
        more code;
    

    still I think this would be more reliable

        for (int i = 0, j = 0, n = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c == '{') {
                if (++n == 1) {
                    j = i;
                }
            } else if (c == '}' && --n == 0) {
                System.out.println(input.substring(j + 1, i));
            }
        }
    
    • 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.