Android: PatternSyntaxException: Syntax error U_ILLEGAL_ARGUMENT_ERROR

前端 未结 1 1729
轻奢々
轻奢々 2021-01-19 11:19

I\'m using json-io for converting some JSON data to Java objects:

DataTransferContainer dataTransferContainer = (DataTransferContainer)JsonReader.jsonToJava(         


        
相关标签:
1条回答
  • 2021-01-19 11:28

    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.

    0 讨论(0)
提交回复
热议问题