-1

I want to group pear orange or beef duck in a second group

category fruits pear orange
category meat beef duck

I tried

https://regex101.com/r/bmipyR/1

(category \b(\w+)\b )((\b\w+\b)+)
user310291
  • 36,946
  • 82
  • 271
  • 487
  • [`^category [a-z]+ (.+)$` and get the first match](https://regex101.com/r/tuX9eK/1), and then group them. It looks from your example you don't want to use `single-line` but `multi-line`. – Andy Jun 07 '22 at 22:53

1 Answers1

0

Your current code doesn't consider spaces.

(category \b(\w+)\b )((?:\b\w+ ?)+)

handles this by making room for an optional space after each word.

Consider also using a multiline flag and anchoring the front and end of each line.

ggorlen
  • 44,755
  • 7
  • 76
  • 106