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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:58:43+00:00 2026-05-30T06:58:43+00:00

I’m looking for a regular expression, but can’t find. Parsing a text file looking

  • 0

I’m looking for a regular expression, but can’t find.

Parsing a text file looking like that

    <resource name="/_op_sox/Project/Default/ICDocumentation/Evaluation/Allianz/Allianz SE/Eval_01241.txt"
              inheritAcls="true">
        <bundle name="AZEvaluation">
            <property name="End Date">
            </property>
            <property name="Evaluation Type">
                <propertyValue name="RCSA"/>
            </property>
        </bundle>
    </resource>
    <resource name="/_op_sox/Project/Default/ICDocumentation/Evaluation/Allianz/Allianz SE/Eval_01481.txt"
              inheritAcls="true">
        <bundle name="AZEvaluation">
            <property name="End Date">
            </property>
            <property name="Evaluation Type">
                <propertyValue name="TRA"/>
            </property>
        </bundle>
    </resource>
   <resource name="/_op_sox/Project/Default/ICDocumentation/Evaluation/Allianz/Allianz SE/Eval_01362.txt"
              inheritAcls="true">
        <bundle name="AZEvaluation">
            <property name="End Date">
            </property>
            <property name="Evaluation Type">
                <propertyValue name="RCSA"/>
            </property>
        </bundle>
    </resource>

My current regex matches to much.

<resource.+?<propertyValue name="RCSA".+?</resource>

It matches the first resource tag and the second + third.
Can somebody change the regex that it really stops at the first </resource>

I use this Java code

Pattern.compile("<resource.+?<propertyValue name=\"RCSA\".+?</resource>",Pattern.MULTILINE | Pattern.DOTALL)
  • 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-05-30T06:58:44+00:00Added an answer on May 30, 2026 at 6:58 am

    I solved it with this Expression: <resource(?:(?!<propertyValue).)+<propertyValue name="RCSA"(?:(?!<resource).)+</resource> but it’s to slow.
    So I looked a bit around what else can be done in Java and found an easy and fast solution.

        Pattern p = Pattern.compile("<resource name=.+?</resource>",
                Pattern.MULTILINE | Pattern.DOTALL);
        String in = getStringFromFile(path, name, pre, count);
        System.out.println("Länge: " + in.length());
        Matcher m = p.matcher(in);
        StringBuffer sb = new StringBuffer();
        int c = 0;
        while (m.find()) {
            m.appendReplacement(sb, getReplacementStage1(m, c++));
        }
        m.appendTail(sb);
        writeStringToFile(path, name, pre, count, sb.toString());
    

    So first I use an easier and faster RegEx and then instead of using String.replaceAll I use the matcher to have the chance to calculate the replacement for every find.

    private static String getReplacementStage1(Matcher m, int c) {
        Pattern p1 = Pattern.compile(
                "<resource[^>]*?contentType=\"Evaluation\"", Pattern.MULTILINE
                        | Pattern.DOTALL);
        Matcher m1 = p1.matcher(m.group());
        if (!m1.find()) {
            // remove
            return "";
        }
        Pattern p2 = Pattern.compile("<propertyValue name=\"(?:RCSA|TRA)\"",
                Pattern.MULTILINE | Pattern.DOTALL);
        Matcher m2 = p2.matcher(m.group());
        if (m2.find()) {
            // remove
            return "";
        }
        // no change, return the group
        return m.group();
    }
    

    So may be this solution helps somebody with a similar problem, that don’t likes/needs an XML parser…

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.