user3639768
user3639768

Reputation: 121

Group inside group

/(test|test1|is(cold|warm|large|small))/

iscold / iswarm / islarge / issmall are two different groups since "is" is from group1 and everything behind it is from group 2. How can I make it into one group so iscold|iswarm|islarge|issmall should be one group, without having to type "is" everytime infront of it.

Upvotes: 10

Views: 8142

Answers (2)

mpcabd
mpcabd

Reputation: 1807

Use non capturing groups for the sub parts.

/(test|test1|is(?:cold|warm|large|small))/

Upvotes: 4

Robin
Robin

Reputation: 9644

Technically, they are already in the same group (number 1). You just match the cold/warm... part in a second group too, which apparently you don't care about.

If you want to avoid this useless capture, you can use a non capturing group (?:...);

/(test|test1|is(?:cold|warm|large|small))/

Upvotes: 8

Related Questions