Home > Mobile >  regex to group multiple words in a separate group
regex to group multiple words in a separate group

Time:06-08

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) )

CodePudding user response:

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.

  • Related