Reputation: 6431
I need to detect that current text contains following keywords "guest post", "guest post", "guest contributor","guest-etc".
i can write query as below.
"guest.?post|guest.?write|guest.?contributor|guest.?etc"
I am looking for a way to make this regex query shorter.
Upvotes: 1
Views: 48
Reputation: 240978
If "guest" is constant, then you can move it out of the alternations:
guest.?(?:post|write|contributor|etc)
Upvotes: 2
Reputation: 781255
Put the common prefix outside a group, and the alternatives inside the group.
guest.?(?:post|write|contributor|etc)
Upvotes: 2