Bảo Lân
Bảo Lân

Reputation: 21

Regex for ending string and containing two other strings

Conditions:

  1. End with abc AND include 123
  2. Include 456

My current regex is (abc$)(123)|456 but it doesn't work.

Upvotes: 0

Views: 50

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626932

You can use

^(?=.*456).*123.*abc$

Details:

  • ^ - start of string
  • (?=.*456) - a positive lookahead that requires any zero or more chars other than line break chars as many as possible, and then 456 immediately to the right of the current location
  • .* - any zero or more chars other than line break chars as many as possible
  • 123 - a literal value
  • .* - any zero or more chars other than line break chars as many as possible
  • abc - an abc string
  • $ - end of string.

Upvotes: 1

Related Questions