Matches whatever regular expression is inside the parentheses, and
indicates the start and end of a group; the contents of a group can be
retrieved after a match has been performed, and can be matched later
in the string with the \number special sequence, described below. To
match the literals '(' or ')', use ( or ), or enclose them inside a
character class: [(] [)].
A more straightforward solution将使用^{} /^{} :
如果您想坚持使用
^{pr2}$split()
,可以use a lookbehind:(即使年份在字符串的末尾,也可以这样做,因为
split()
返回一个数组,其中包含原始字符串,以防找不到分隔符。)您可以同时使用
split()
和search()
,假设您的字符串中有一个这样的日期。在给予
^{pr2}$以及
给予
如果它总是相同的模式,那么为什么不呢:
对于原始正则表达式,由于未捕获匹配的组,因此它不是匹配项的一部分:
^{pr2}$()
将选择标记为captured group:相关问题 更多 >
编程相关推荐