0

I have a String containing natural numbers and between of them any pattern like (,-) or (,). With a while - condition i make sure that the given Strings contains as less numbers as a given window size, e.g. 5.

The condition looks like that:

while(discretizedTs.substring(lagWindowStart).matches("(-?,?\\d+,){5,}")) {
}

Where lagWindowStart jumps to the index of the next number or (-,) pattern. For small Strings this regular expression is working fine (as far as tested). My Problem is, that for large Strings (and i have to deal with very large Strings normaly) this regular expression caused an SOF. This happens for example if the String contains more than 17k characters.

Is there a limitation of the length of a String which is to match? or a limit in time the matching must be completed? I did not know how to solve the given problem without regular expressions. I hope you have any ideas..

Thank you best

5
  • What is the language? Looks like Java? (It would help if you post a bit more code). If the input contains spaces, you can split the input up by space, or you can split it up by [^-,\d]+ since your regex has nothing to do with the rest of the characters. Commented Nov 18, 2012 at 2:30
  • Can't you just write a loop? Commented Nov 18, 2012 at 2:49
  • Yes it is java. I do not know further parts of code to post.. The Strings looks like "1,1,3,4,3,-,4,5,4,3,4,-,43,4,4,6,-" and so on.. i slide a window throw it and must be take care, that the String contains minimum n numbers. where n is the window size. the outer (error throwing) while - condition check if (first iteration)"10,1,3,4,3,-,4,5,4,3,4,-,43,4,4,6,-" contains as least n numbers, (second..) "1,3,4,3,-,4,5,4,3,4,-,43,4,4,6,-" contains as least n numbers and so on (,###, is ONE number here) Commented Nov 18, 2012 at 2:51
  • the problem is that inner while loops lokks like while (temp_lag.matches("(-?,?\\d+,){"+lag_leadWindowSize+"}")==false){ do smthg;} but this would also match words with less numbers then the windowsize.. Sorry.. forgotten to say that the outer loop have to check if the String contains two times the windowsize many numbers. if the windowsize is 5 the outer loop have 10 as minimum. therefore i need two loops... it is hard to explain.. Commented Nov 18, 2012 at 3:15
  • Thank you. i worked around this problem by checking if the String has enough numbers before in a loop by adding number per number to a temporary string so i process never the whole string. that helps "{n}" quantifier instead of {n,} Commented Nov 18, 2012 at 17:46

1 Answer 1

1

Default JVM stack size is rather small. You can increase it with -Xss option, eg -Xss1024k, should help.

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.