我想找到空格和|。
之间的字符我使用的是以下表达式,但无法获得正确的输出。
@"\s\S*[|]\b"
答案 0 :(得分:4)
你可以使用这个:
(?<=\s)[^\|]*(?=\|)
Anubhava的答案也是正确的,但是在的情况下
String : "Helllo good day |on a go|there you are"
Match : "good day ", "a go", "you are" // Anubhava's
Match : "good day ", "a go" // this one
// "you are" should not be matched as not in between space and |. | is not there at the end
这个正则表达式有三个部分:
(?<=\s)
:回顾一个空间[^\|]*
:除<| li>以外的任何内容
(?=\|)
:向前看| 所以,(?<=\s)[^\|]*(?=\|)
合在一起会匹配前面有 space( )
的序列,之后有 |
的序列把他们包括在比赛中。
答案 1 :(得分:1)
您可以使用此正则表达式:
"(?<=\s)[^|]*"
答案 2 :(得分:0)