-2

I have this JavaScript Regex: /(\.abc$|^abc$|abc\.def$)/i. I feel like this is extremely redundant and it can be simplified. Here's what I'm trying to accomplish:
- It needs to match .abc only at the end or only abc or only abc.def

Edit: I realized I could place $ at the end of the parenthesis and it could become /(\.abc|^abc|abc\.def)$/i. However, this still seems redundant

John Boyer
  • 27
  • 3

1 Answers1

0

You can only combine two of the options at a time because of the fork implied by .abc.def not matching at the end.

SO each case combines two and adds the remaining option:

(^abc(\.def)?|\.abc)$

((^|\.)abc|^abc\.def)$
NetMage
  • 26,163
  • 3
  • 34
  • 55