user3146259
user3146259

Reputation: 3

Combining two regular expressions into one

I need to combine these 2 regexes ^.*(Completed: BALI - Job).*$ and \b(BALI_)(INVOICES|CORRESPONDENCE|LATE_SCANNINGS)\b into one so that it should match "Completed: BALI - Job" as a mandatory and "BALI_INVOICES or BALI_CORRESPONDENCE or BALI_LATE_SCANNINGS" as alternatives

Upvotes: 0

Views: 140

Answers (2)

Ade YU
Ade YU

Reputation: 2362

As the second part is optional, a ? is appended.

^.*(Completed: BALI - Job).*(\b(BALI_)(INVOICES|CORRESPONDENCE|LATE_SCANNINGS)\b)?

Upvotes: 1

grebneke
grebneke

Reputation: 4494

Expanding on David-SkyMesh's answer, making the first part mandatory, the second part of three alternatives optional:

/ (                                                           # capture
    (?:Completed: BALI - Job)                                 # this
                                                              # AND optionally
                                                              # one of these
    (?:\bBALI_(?:INVOICES|CORRESPONDENCE|LATE_SCANNINGS)\b)?  
  )
/x                       # ignore whitespace & comments in regexp itself

Upvotes: 1

Related Questions