Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex performance issues with possible back tracking?
    text
    copied!<p>I have the following input/output and regex code that works fine (for the below input/output).</p> <p>-- input --</p> <pre><code>keep this keep this too Bye ------ Remove Below ------ remove all of this </code></pre> <p>-- output --</p> <pre><code>keep this keep this too Bye </code></pre> <p>-- code -- </p> <pre><code> String text = "keep this\n \n" + " keep this too\n \n Bye\n------ Remove Below ------\n remove all of this\n"; System.out.println(text); Pattern PATTERN = Pattern.compile("^(.*?)(-+)(.*?)Remove Below(.*?)(-+)(.*?)$", Pattern.DOTALL); Matcher m = PATTERN.matcher(text); if (m.find()) { // remove everything as expected (from about input-&gt;regex-&gt;output) text = ((m.group(1)).replaceAll("[\n]+$", "")).replaceAll("\\s+$", ""); System.out.println(m.group(1)); System.out.println(text); } </code></pre> <p>Ok, so this works great. However, this is for a test with the defined input output. When I get large files that I have to parse that contain the following sequence of characters/patterns I'm seeing the code take a while to execute (4-5sec) per the Find() method on files that are say 100k in size that have the following pattern. In fact sometimes I'm not sure if it's returning or not...when I step though as a debug test the find() method hangs and my client disconnects.</p> <p>NOTE: There is nothing to match in this file...but this is a pattern that is taxing my regex.</p> <p>-- 100k file -- </p> <pre><code>junk here more junk here o o o (even more junk per the ellipses) -------------------------------------this is junk junk here more junk here o o o (even more junk per the ellipses) -------------------------------------this is junk junk here more junk here o o o (even more junk per the ellipses) -------------------------------------this is junk junk here more junk here o o o (even more junk per the ellipses) this repeats from above to make up the 100k file. </code></pre> <p>-- ASK --</p> <blockquote> <p>How can I optimize the above regex to handle large file patterns from above as such or is this normal for regex parse speed (4-6sec) let along hanging altogether?</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload