Android: PatternSyntaxException: Syntax error U_ILLEGAL_ARGUMENT_ERROR

主宰稳场 提交于 2019-12-01 22:06:07

In ICU regex patterns, bracket expression pattern cannot start with :.

You need to change the pattern to

Pattern.compile("(\\d{2})[.:](\\d{2})[.:](\\d{2})[.](\\d{1,10})([+-]\\d{2}:?\\d{2}|Z)?")

Note the changes:

  • [:] is changed to :
  • [:.] is changed to [.:]

The regex library used in Android is ICU, and one of its peculiarities is that it supports POSIX character classes outside bracket expressions. That means you may write [[:digit:]] to match a digit, or [:digit:] (which is invalid in most other regex flavors including POSIX). The ICU regex parser seems to have problems parsing bracket expressions starting with : and surely it is a bug.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!