use Perl Log In
Java finally catches up to Perl (and Python, Tcl)
rjray writes "Over at /. they're reporting that Sun has finally released the first official version of their Java 2 SDK version 1.4. Read the release notes here. Java finally has native support of regular expressions, one of the first things I found lacking when I took a shot at Java programming some time ago. The regex's are even referred to as "Perl-like" in at least one place, maybe more!"
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.

Yeah, but (Score:0)
Not very Perl-like.... (Score:2, Informative)
The example program [sun.com] takes 92 lines to implement a file grep. It implements the pattern .*\r?\n, and if you wonder why that's bad, read Ovid's Death to Dot Star post [perlmonks.org] over at PerlMonks. (I'm presuming the Java regex engine backtracks, like other regex engines I know of.)
Re:Not very Perl-like.... (Score:3, Informative)
Hmmm... now I'm rather curious as to what's going on here. Here's the regex code to match a line:
private static Pattern linePattern
= Pattern.compile(".*\r?\n");
I don't think VSarkiss' criticism of the dot star is appropriate in this case as Java documentation [sun.com] states that the dot does not match a line terminator. However, they appear to have goofed up the line terminator! What about \r on Macs? From what I can tell from their docs, the carriage return/newli
Re:Not very Perl-like.... (Score:2, Informative)
Re:Not very Perl-like.... (Score:0, Redundant)
I only counted the code, not the comments. With the comments it's 135 lines.
Severely b0rken (Score:3, Informative)
Reply to This
Re:Severely b0rken (Score:3, Informative)
Re:Severely b0rken (Score:2)
I don't understand your example. split(/=/, "foo=bar=20", 2) I presume the "2" means "only give me two return values," because you say we'd expect to get two return values. Without the 2 I'd expect to get a list of {foo bar 2}, with the 2 I'd expect to get what you say I wouldn't expect: {foo bar}. Huh?
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Never mind... (Score:2)
Oh, wow! I just learned something about Perl.
I've rarely used the final parameter to split, so I didn't know.
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Re:Never mind... (Score:2)
Regexps are not everything (Score:1)
Perl has other features besides Regexps, which I like very much. Stuff like nested data-structures, dynamic typing, functions as first-order values, closures, eval, multiple-inheritance, etc. etc.
I don't think Java has all that, or should. That's why I still prefer Perl for most purposes.
Perl like regexes for Java (Score:1)
separate java library offers regexp too (Score:1)