GWT Regular Diacritics

If I try to match a regex string with diacritics (something along the lines ^ [a-zA-Z0-9aAAA] {0,100} $), then it will correspond to Báhhh on the server side (I repeat this check twice) but will fail on the client side. I have already changed the id of the java class, but it still does not match.

Is there a special gwt regex class for diacritics or am I missing something?

+4
source share
2 answers

Strange, since /^[a-zA-Z0-9áàAÁÁ ]{0,100}$/.test('Báhhh') returns true for me in the Chrome JS console.

I suspect this is a Unicode problem where á can be encoded in several ways: U + 0061 U + 0301, U + 0061 U + 0341 or U + 00E1.

Perhaps try /^(?:[a-zA-Z][\u0301\u0341]?|[áàÁÁ0-9 ]){0,100}$/

+1
source

Java and JavaScript regex have differences in implementations that may not always be clearly visible. I suggest you use different validators for each case - take a look at the RegExp class in GWT :

There are several small incompatibilities between the two Implementations. Java-specific constructs in the regex syntax (for example, [az && [^ bc]], (<= foo), \ A, \ Q) work only in the pure Java implementation, not the GWT implementation, and do not reject either . In addition, the Javscript-specific constructions of $ `and $ 'in the substitution expression work only in the GWT implementation, and not in the pure Java implementation, which rejects them.

+1
source

Source: https://habr.com/ru/post/1396377/


All Articles