Hmm, looks fine to me. I forget why, but I abandoned using RegExp
objects in GWT way back when I first started using GWT. I don't see
RegExp in the JRE emulation reference, so that's probably why. All I
know is that I just use String.matches(), but I don't know how to do
modifiers like "gi" for global and ignorecase... I just use
String.toLowerCase().
Oh, look here, I have my own RegExp class (that I got mostly or all
from someone else) that I don't even use.
<code>
public class RegExp extends JavaScriptObject
{
protected RegExp()
{
}
public static native RegExp create(String exp)/*-{
return new $wnd.RegExp(exp);
}-*/;
public static native RegExp create(String exp, String
modifiers)/*-{
return new $wnd.RegExp(exp,modifiers);
}-*/;
public final boolean test(String sToMatch)
{
return test(this, sToMatch);
}
public final String[] exec(String sToMatch)
{
return exec(this, sToMatch);
}
public final int lastIndex()
{
return lastIndex(this);
}
private static native boolean test(RegExp self, String
sToMatch)/*-{
return self.test(sToMatch);
}-*/;
private static native String[] exec(RegExp self, String
sToMatch)/*-{
return self.exec(sToMatch);
}-*/;
private static native int lastIndex(RegExp self)/*-{
return self.lastIndex;
}-*/;
}
</code>
On Feb 16, 5:05 pm, xgeoff <[email protected]> wrote:
> I have the following regular expression:
>
> \S*\.(jpg|gif|png)$
>
> which I have tested in multiple online Javascript testers, and it works.
> The intent is to match filenames for image files. (e.g.
> "myimagefilename.jpg").
>
> my code to set this up is below. When I step through it I find the
> following:
>
> 1. The regular expression looks valid, meaning at runtime the
> IMAGE_FILE_PATTERN has proper javascript form: /\S*\.(jpg|png|gif|bmp)$/gi
> 2. The following filename -> "DSC_0001.JPG" evaluates to false when tested
> against the IMAGE_FILE_PATTERN.
> 3. The ignoreCase attribute returns true on the IMAGE_FILE_PATTERN.
>
> Anyone have any suggestions on why this keeps evaluating to false with all
> of my image file names?
>
> public class MyClass {
>
> protected static final RegExp IMAGE_FILE_PATTERN = RegExp.compile(
> "\\S*\\.(jpg|png|gif|bmp)$", "gi");
>
> public CarouselWidget(JSONArray fileList) {
>
> Image img;
>
> JSONValue val;
>
> JSONString jString;
>
> String urlFragment;
>
> boolean match;
>
> int size = fileList.size();
>
> for(int index=0; index<size; index++) {
>
> val = fileList.get(index);
>
> jString = val.isString();
>
> if (jString != null) {
>
> urlFragment = jString.toString();
>
> match = IMAGE_FILE_PATTERN.test(urlFragment);
>
> @SuppressWarnings("unused")
>
> boolean ignoreCase = IMAGE_FILE_PATTERN.getIgnoreCase();
>
> if (match) {
>
> img = new Image(ImageBrowserEntryPoint.baseUrl + "/" + urlFragment);
>
> img.addClickHandler(new ImageClickHandler(tPanel, urlFragment));
>
> hPanel.add(img);
>
> }
>
> }
>
> }
>
>
>
>
>
>
>
> }
> }
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.