how to get regex(Pattern and Matcher) working in client side

985 views
Skip to first unread message

anjan bacchu.dev

unread,
Nov 11, 2010, 2:03:14 PM11/11/10
to google-we...@googlegroups.com

We're using GWT 2.03 along with SmartGWT 2.2. I'm trying to use a regex like below in client side code.

Pattern pattern = Pattern.compile("\\\"(/\d+){4}\\\"");
String testString1 = "[    \"/2/4/5/6/8\",    \"/2/4/5/6\"]";
String testString2 = "[  ]";

Matcher matcher = pattern.matcher(testString1);
boolean result = false;
while (matcher.find()) {
   
System.out.println(matcher.group());
}

It appears that Pattern and Matcher classes are NOT compiled to Javascript by the GWTC compiler and hence this application did NOT load. What is the equivalent GWT client code so that I can find regex matches within a String ?

How have you been able to match regexes within a String in client-side GWT ?

Thank you,

Jim Douglas

unread,
Nov 11, 2010, 2:34:56 PM11/11/10
to Google Web Toolkit
This can be used in GWT client code:

http://download.oracle.com/javase/6/docs/api/java/lang/String.html#matches(java.lang.String)

(Of course, you still need to be aware of the differences between Java
and JavaScript regex implementations).

To see if a given Java feature will work in GWT client code, see:

http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html

Thomas Broyer

unread,
Nov 11, 2010, 6:18:10 PM11/11/10
to Google Web Toolkit


On 11 nov, 20:34, Jim Douglas <jdou...@basis.com> wrote:
> This can be used in GWT client code:
>
> http://download.oracle.com/javase/6/docs/api/java/lang/String.html#ma...)
>
> (Of course, you still need to be aware of the differences between Java
> and JavaScript regex implementations).
>
> To see if a given Java feature will work in GWT client code, see:
>
> http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html

See also http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/regexp/shared/RegExp.html
which mimics the JS RegExp API and can also be used on the server-side
(or unit tests without GWTTestCase).

lineman78

unread,
Nov 11, 2010, 8:32:07 PM11/11/10
to Google Web Toolkit
Thats nice that they finally added full regex capability. If you need
to access a capture group in older versions of GWT use this:

public static native String getRegexGroup(String toSearch, String
regex, int groupNum)
/*-{
return toSearch.match(regex)[groupNum];
}-*/;

Or if you need to access multiple groups use this:

public static native JsArrayString getRegexResult(String toSearch,
String regex)
/*-{
return toSearch.match(regex);
}-*/;

On Nov 11, 4:18 pm, Thomas Broyer <t.bro...@gmail.com> wrote:
> On 11 nov, 20:34, Jim Douglas <jdou...@basis.com> wrote:
>
> > This can be used in GWT client code:
>
> >http://download.oracle.com/javase/6/docs/api/java/lang/String.html#ma...)
>
> > (Of course, you still need to be aware of the differences between Java
> > and JavaScript regex implementations).
>
> > To see if a given Java feature will work in GWT client code, see:
>
> >http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html
>
> See alsohttp://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/g...

anjan bacchu.dev

unread,
Nov 15, 2010, 1:40:34 AM11/15/10
to google-we...@googlegroups.com
Hi thomas,
 
  Thank you.
 
  Is there a way to backport this onto 2.0.3 ? We're gone Production using 2.0.3 and it would help to know what it takes to backport to 2.0.3.
 
Thank you,
 
BR,
~A


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Reply all
Reply to author
Forward
0 new messages