“^^^”上的正则表达式Java拆分字符串
我希望有人能帮我设计一种模式,严格按照三个^
的字符序列分割字符串,即^^^
Input: Sample-1^^^Sample-2
Output: String 1: Sample-1 and String-2: Sample-2
我试过\\^\\^\\^
,它对快乐之路很有效。但如果我给它一个字符串,比如:
Input: Sample-1^^^^Sample-2
我得到的输出是:
String 1: Sample-1
String-2: ^Sample-2
我也尝试了这个模式,但没有成功
# 1 楼答案
在这种情况下,您需要匹配} ):
one or more
文字^
字符的\^+
(^{或者,如果只想匹配
3 or 4
文字^
字符,可以使用:或者,如果要匹配
3 or more
文字^
字符,可以使用: