Reputation: 185
I want to find characters that should come between space and |.
I am using the below expression but I could not get correct output.
@"\s\S*[|]\b"
Upvotes: 0
Views: 75
Reputation: 3802
You can use this one :
(?<=\s)[^\|]*(?=\|)
Anubhava's answer is also correct, but in case of
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
this regex has three parts:
(?<=\s)
: look-back for one space[^\|]*
: anything other than |(?=\|)
: look-ahead for |so, together (?<=\s)[^\|]*(?=\|)
will match the sequence which has a space( )
before it, and a |
after, without including them in the match.
You can test the regex here.
Upvotes: 4
Reputation: 2489
Use this regular expression:
/\ ([^ \|]*)\|/
You can test this regular expression on Rubular
Upvotes: 0