REGEX find words in upper case and words followed by a single special character

Could someone help me. I’m trying to parse this string using regex in javascript:

BMB-001 RING/MESH T-Bar Track T-BAR W/

My Goal is to match RING, MESH, T-BAR and W/ only.

I’m currently using this regex: (b[^dW][A-Z-'/]['A-Z]+|b[A-Z][-/$]), But the result matched BMB, RING, MESH, T-B,T-BAR and W/

Answer

You can use

b[A-Z]+(?:[-'][A-Z]+)*(?:/|(?!S))

See the regex demo. Details:

  • b – a word boundary
  • [A-Z]+ – one or more uppercase letters
  • (?:[-'][A-Z]+)* – zero or more occurrences of - or ' and one or more uppercase letters
  • (?:/|(?!S)) – a / or a location not immediately followed with a non-whitespace char.