Jas
Jas

Reputation: 15103

regular expression multiple characters within or

is it possible to capture only multiple characters within 'or'?

i would like this [(abc)(cde)] to capture abc or cde however it captures ( or a or b or c or ) ...

i saw this: regular-expression-capture-groups-which-is-in-a-group

is what i'm asking not possible in regular expressions? it sounds too obvious and far needed, for me not to exist in it...

Upvotes: 1

Views: 123

Answers (2)

pms1969
pms1969

Reputation: 3704

(abc|cde) should work for you.

Upvotes: 0

Tim Pietzcker
Tim Pietzcker

Reputation: 336148

You want this:

(abc|cde)

This matches either abc or cde and captures the result in a backreference. If you don't need the backreference, use

(?:abc|cde)

Another hint: If you want to make sure that you only match entire words, not substrings within a longer word like abc within tabcontrol, use word boundaries:

\b(abc|cde)\b

Upvotes: 4

Related Questions