java vs javascript regex

1,786 views
Skip to first unread message

sunn...@gmail.com

unread,
Jul 4, 2012, 3:58:23 AM7/4/12
to Google Web Toolkit
Hi all, I've read that there are differences between the Java and
Javascript regex patterns, so you'll get different behaviour when it
dev/hosted/prod mode using regex.

I'm trying to do a split which includes the delimiter to process camel
case text. In simpler form (forgetting acronyms and such):
String regex = "(?=[A-Z])";
String[] words = camelCase.split(regex);
// go on to capitalise each word

This works in dev mode - straightforward java regex. But this doesn't
work as expected in prod mode. Then through a little trial and error
here: http://www.pagecolumn.com/tool/regtest.htm (click the "Return"
tab to see the evaluated output)

This piece of javascript did what I wanted.
var myArray = str.split(/(?=[A-Z])/g)

So off I went and plucked "/(?=[A-Z]/g" into my
camelCase.split(regex), but it appears to be just returning the entire
string.

Test browser is FF12.

Joseph Lust

unread,
Jul 4, 2012, 9:07:21 AM7/4/12
to google-we...@googlegroups.com
Be sure that you're using the GWT RegExp wrapper.

See earlier similar post: RegExp not matching, but it should

Sincerely,
Joseph

sunn...@gmail.com

unread,
Jul 4, 2012, 8:20:07 PM7/4/12
to Google Web Toolkit
Thanks! Using the same regex pattern but with GWT RegExp did the
trick :)

On Jul 4, 11:07 pm, Joseph Lust <lifeofl...@gmail.com> wrote:
> Be sure that you're using the GWT RegExp wrapper<http://google-web-toolkit.googlecode.com/svn/javadoc/2.2/com/google/g...>
> .
>
> See earlier similar post: RegExp not matching, but it should<https://groups.google.com/forum/?fromgroups#!searchin/Google-Web-Tool...>
>
> Sincerely,
> Joseph
Reply all
Reply to author
Forward
0 new messages