今日由于工作需求,做了一些截取拼接URL的操作,频繁用到split(), 结果报错PatternSyntaxException,看方法描述后得知这个方法其实要求传的是正则,方法描述如下:
Splits this string using the supplied regularExpression. Equivalent to split(regularExpression, 0). See Pattern.split(CharSequence, int) for an explanation of limit. See Pattern for regular expression syntax.
If the same regular expression is to be used for multiple operations, it may be more efficient to reuse a compiled Pattern.
-
Parameters:
- regularExpression Throws:
-
NullPointerException - if
regularExpression == null - PatternSyntaxException - if the syntax of the supplied regular expression is not valid. Since:
- 1.4 See Also:
- Pattern
如下:
以前经常用,只知道能截取字符串变成数组,又涨了姿势。学而时习之,不亦说乎。

本文介绍如何利用正则表达式处理URL,并详细解释了正则表达式的基本语法及常见错误,如PatternSyntaxException。同时分享了在实际编程中如何避免这些错误。
1323

被折叠的 条评论
为什么被折叠?



