Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex to find substring

Tags:

java

regex

Say I have a substring BB which may be alone or part of a longer string, e.g. BB or AA|BB|CC or BB|CC or AA|BB i.e. if it follows/is followed by another substring it MUST be separated by a |. What regex do i need to find BB in any of the above but not in say AABB?

like image 499
user580459 Avatar asked Jun 04 '11 18:06

user580459


1 Answers

I think this will do it:

^(.+[|])?BB([|].+)?$

And after testing here I'm going to say yes, this is it.

like image 132
Chris Eberle Avatar answered Sep 21 '22 02:09

Chris Eberle