Subject: [Ltru] Java regex for draft-16...

From: "Phillips, Addison" <[email-masked]>
Date: Thu, 12 Jun 2008 13:13:09 -0700

Some time ago I gave Stephane a Java regex for 4646 (you can find it in langtag.net). Here is my current 4646bis (draft-16) regex. Even better: this one works properly (lookahead is used to prevent the greedy quantifiers from eating what they should not).

Note that this one does not include the irregular production, which is left as an exercise to the user.

        static final String langtag_ex =
        "([xX]([\\x2d]\\p{Alnum}{1,8})*)|(((\\p{Alpha}{2,8})"
          + "(([\\x2d]\\p{Alpha}{3})(?=\\x2d|\\z)){0,3}"
        + "([\\x2d]\\p{Alpha}{4}(?=\\x2d|\\z))?"
        + "([\\x2d](\\p{Alpha}{2}|\\d{3})(?=\\x2d|\\z))?"
        + "([\\x2d](\\d\\p{Alnum}{3}|\\p{Alnum}{5,8}))*)"
        + "(([\\x2d]([a-wyzA-WYZ])([\\x2d](\\p{Alnum}{2,8})+)*))*"
        + "([\\x2d][xX]([\\x2d]\\p{Alnum}{1,8})*)?)";

Bug reports welcome. Stephane: you are welcome to publish this as a replacement.

Addison

Addison Phillips
Globalization Architect -- Lab126

Internationalization is not a feature.
It is an architecture.

_______________________________________________
Ltru mailing list
[email-masked]
https://www.ietf.org/mailman/listinfo/ltru

---

From: "Mark Davis" <[email-masked]>
Date: Thu, 12 Jun 2008 14:11:21 -0700

I'd be wary of this. Alnum is more than [a-zA-Z0-9], etc.

Mark

On Thu, Jun 12, 2008 at 1:13 PM, Phillips, Addison <[email-masked]>
wrote:

> Some time ago I gave Stephane a Java regex for 4646 (you can find it in
> langtag.net). Here is my current 4646bis (draft-16) regex. Even better:
> this one works properly (lookahead is used to prevent the greedy quantifiers
> from eating what they should not).
>

---

From: "Phillips, Addison" <[email-masked]>
Date: Thu, 12 Jun 2008 14:19:20 -0700

There are one or two other bugs in it (reminder to self: run all JUnits before sending emails about it). However, the Javadoc for Pattern says the POSIX classes (\\p{mumble}) really mean a-zA-Z0-9. Cursory tests suggest this is true. Is the javadoc wrong? I know, of course, that the Unicode classes are far bigger, but regex has other ways of accessing those. (My current expression follows)

      static final String langtag_ex =
        "(\\A[xX]([\\x2d]\\p{Alnum}{1,8})*\\z)"
        + "|(((\\A\\p{Alpha}{2,8}(?=\\x2d|\\z)){1}"
        + "(([\\x2d]\\p{Alpha}{3})(?=\\x2d|\\z)){0,3}"
        + "([\\x2d]\\p{Alpha}{4}(?=\\x2d|\\z))?"
        + "([\\x2d](\\p{Alpha}{2}|\\d{3})(?=\\x2d|\\z))?"
        + "([\\x2d](\\d\\p{Alnum}{3}|\\p{Alnum}{5,8})(?=\\x2d|\\z))*)"
        + "(([\\x2d]([a-wyzA-WYZ](?=\\x2d))([\\x2d](\\p{Alnum}{2,8})+)*))*"
        + "([\\x2d][xX]([\\x2d]\\p{Alnum}{1,8})*)?)\\z";

Of course, one can s/Alnum/[a-zA-Z0-9] and s/Alpha/[a-zA-Z]

Addison

Addison

Addison Phillips

From: [email-masked] [mailto:[email-masked]] On Behalf Of Mark Davis
Sent: Thursday, June 12, 2008 2:11 PM
To: Phillips, Addison
Cc: Stephane Bortzmeyer; [email-masked]
Subject: Re: [Ltru] Java regex for draft-16...

Mark
On Thu, Jun 12, 2008 at 1:13 PM, Phillips, Addison <[email-masked]<mailto:[email-masked]>> wrote:
Some time ago I gave Stephane a Java regex for 4646 (you can find it in langtag.net<http://langtag.net>). Here is my current 4646bis (draft-16) regex. Even better: this one works properly (lookahead is used to prevent the greedy quantifiers from eating what they should not).

Addison

Addison Phillips

_______________________________________________
Ltru mailing list
[email-masked]<mailto:[email-masked]>
https://www.ietf.org/mailman/listinfo/ltru

---

From: John Cowan <[email-masked]>
Date: Thu, 12 Jun 2008 17:31:05 -0400

Phillips, Addison scripsit:

> There are one or two other bugs in it (reminder to self: run all JUnits
> before sending emails about it). However, the Javadoc for Pattern
> says the POSIX classes (\\p{mumble}) really mean a-zA-Z0-9. Cursory
> tests suggest this is true. Is the javadoc wrong? 

A quick look at OpenJava confirms that the Posix escapes are interpreted
relative to ASCII only (which is not very Posix of them).  However,
I'd make the obvious substitutions, if only because \p{Alnum} means
something different in other kinds of regexes.

-- 
They tried to pierce your heart                 John Cowan
with a Morgul-knife that remains in the         http://www.ccil.org/~cowan
wound.  If they had succeeded, you would
become a wraith under the domination of the Dark Lord.         --Gandalf
_______________________________________________
Ltru mailing list
[email-masked]
https://www.ietf.org/mailman/listinfo/ltru