Ondrej Stastny
Ondrej Stastny

Reputation: 159

JavaScript regex with back reference

I would like to construct regex (in JavaScript) that would return:

Is that possible?

Upvotes: 0

Views: 358

Answers (1)

Qtax
Qtax

Reputation: 33908

Could be done with:

/(?=(test))(test-a)?/

Replace test and a with the pattern you are really looking for.

You may also want to anchor it, eg:

/^(?=(test))(?=(test-a)?)test(?:-a)?$/

Upvotes: 2

Related Questions