1

I have a huge string which I would like to match to the following regex:

"\\s*<?.*?>\\s*<abc>[\\s\\S]*|\\s*<abc>[\\s\\S]*"

as in

myHugeString.matches("\\s*<?.*?>\\s*<abc>[\\s\\S]*|\\s*<abc>[\\s\\S]*"));

The string is enormous, so matching the [\s\S]* at the end is taking up a huge amount of time. I am looking to only match the first portion (\\s*<?.*?>\\s*<abc>), and I don't care about anything after that.

What would be the most efficient way of going about this

Thanks

1 Answer 1

1

You can use Pattern and Matcher classes here:

Sample Code:

Pattern pattern = Pattern.compile("\\s*<?.*?>\\s*<abc>|\\s*<abc>");
Matcher matcher = pattern.matcher(yourString);

if (matcher.find()) {
    // Pattern found.
}

You can even shorten your regex pattern to:

"(?:\\s*<?.*?>)?\\s*<abc>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.