0

My current regex

^Service\.LT\.fix\.log$

matches the below string

Service.LT.fix.log

How would I change regex so any word before and after LT should pass.

The regex should pass all the below cases:

Service.LT.fix.log
Service.BeforeLT.fix.log
Service.LTAfter.fix.log

I tried

^Service\..+?LT.+?\.fix\.log$ 

but that did not work.

user3809938
  • 1,114
  • 3
  • 16
  • 35
  • 5
    Use `.*?` instead of `.+?`, that will allow the matching of *nothing* – Jerry Jan 16 '19 at 12:54
  • that works, but i am not sure why using + didnt – user3809938 Jan 16 '19 at 12:58
  • The `+` quantifier means 1 or more, whereas `*` means 0 or more. Using `.+?` in your regex is like saying there must be at least *something* before `LT`, but this *something* cannot be *nothing*, it needs to be at least of length 1. – Jerry Jan 16 '19 at 13:00

1 Answers1

0

Try:

^Service\.\w*LT\w*\.fix\.log$

Franco Piccolo
  • 6,845
  • 8
  • 34
  • 52