Java regexes support controversy

I was reading a JDK1.4 book and I came across the following:

 “Java supports regexes through a library rather than a specialized syntax, which is a feature or a bug, depending on who you talk to. Other than this, however, Javas regex support is quite strong.”

Does anyone have info on the controversy? Any thread or document that addresses the use of a library rather than a specialized syntax? Also whats the general feedback on regexes thro Java. It seems to me that the performance would depend on the selection of library implementation. I found a whole slew of implementations here.

Advertisements

2 thoughts on “Java regexes support controversy”

  1. The statement means that Java supports regular expressions through the API, rather than through language extensions.

    Other languages (e.g. Perl) use language syntax successfully.

    I suspect that the person who made the claim you quoted was pointing out that Java didn’t opt for a syntax extension like this:

    String fullName = “Sheldon Hearn”;
    if (fullName !~ /^[A-Za-z]+\s+[A-Za-z]+$/) {
    throw new Error(
    “Not a simple name: ” + fullName
    );
    }

    Here, the language syntax supports !~ as “does not match the following regular expression” and / as a regular expression delimiter when following a regular expression match operator.

    Instead, you need to use API features, e.g.

    String fullName = “Sheldon Hearn”;
    if (!fullName.matches(
    “^[A-Za-z]+\s+[A-Za-z]+$”
    ) {
    throw new Error(
    “Not a simple name: ” + fullName
    );
    }
    }

    That’s fine for this example, but gets awkward when the regular expression contains escaped characters. That’s because the escape character for both literal strings and regularr expressions is the backslash. So you end up with pretty unradable regular expressions quite quickly.

    P.S. Either HTML syntax should be enabled, or my whitespace should be preserved. 🙂

  2. There was something very funny I read on the web about Perl:

    Perl: The only language that looks the same before and after RSA encryption. (Keith Bostic)

    or

    The three characteristics of Perl programmers: mundaneness, sloppiness, and fatuousness. (Xah Lee)

    but to me every language has its own pros and cons… one should use the language he or she wishes if he or she finds it suitable for solving his problem

    There are some other nice quotes available at http://www.sysprog.net/quotjava.html

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s