We're using GWT 2.03 along with SmartGWT 2.2. I'm trying to match 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,
Just use the String class to do it! Like this:
String text = "google.com";
if (text.matches("(\\w+\\.){1,2}[a-zA-Z]{2,4}"))
System.out.println("match");
else
System.out.println("no match");
It works fine like this, without having to import or upgrade or whatever. Just change the text and regex to your liking.
Greetings, Glenn
Consider upgrading to GWT 2.1 and using RegExp
.
Use GWT JSNI to call native Javascript regexp:
public native String jsRegExp(String str, String regex)
/*-{
return str.replace(/regex/); // an example replace using regexp
}
}-*/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With