Re: buggy regexp
On 31.05.2007 16:33, ilyabo@xxxxxxxxx wrote:
Hello all!
The following line hangs in Java:
Pattern.matches("((<BR>)|([^<>]+))*", "aaaaaaaaaaaaaaaaaaaaaaaa
<BR><Bx>")
What's wrong with the regular expression?
You nest "+" and "*" which can lead to bad backtracking (which you seem
to experience). If you wait long enough you'll see the result.
If you just want to test for the presence of "<BR>" you can do this:
boolean match = str.indexOf("<BR>") != -1;
Or as regexp
Pattern p = Pattern.compile("<BR>");
boolean match = p.matcher(s).find();
Kind regards
robert
.
Relevant Pages
- Re: rant: why is it acceptable to be this... lazy?
... Java 6 regular expression stuff to do just about everything. ... The existing XML-parsing feeping creature lurking in the SAX ... (comp.lang.java.programmer) - Re: Making file name unique
... I'm using Java 1.5. ... I am downloading files over an FTP ... I do require this specific numbering. ... anything about using a regular expression of the type Lars wrote. ... (comp.lang.java.programmer) - Re: [opensuse] OpenOffice.org 3.1(and prev versions) locking up?
... there is no need to kill the process (OO-Writer) when it ... hangs, as mostly it recovers by itself. ... This option is available in Tools - Options - OpenOffice.org - Java ... (SuSE) - Re: Regexp question: Trouble matching with backslash
... Backslashes have to be escaped in Java ... regular expression. ... Using an arbitrary String as a regexp is gambling ... (comp.lang.java.programmer) - Re: Bizarre benchmark result -- C# hundreds of times slower than Java?
... Reportedly, the same program in C# is much, much slower than in Java. ... it is a benchmark of the regular expression implementations. ... There is no point in compiling the regular expression into an assembly if its to be executed once, ... If anything, it tells you that of the two programs, the java one completed, and the C# one didn't and ran a lot slower to boot. ... (microsoft.public.dotnet.languages.csharp) |
|