0

I have a large project that has many *.html files and many *.tpl.html files.

I want to use a regular expression that allows me to differentiate between these two for my Webpack config.

I have tried using laziness to achieve this, like .*?\.html but this also matches *.tpl.html. https://regex101.com/r/a0fl4H/1

How can this be achieved?

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
alanbuchanan
  • 3,993
  • 7
  • 41
  • 64

2 Answers2

3

Try this:

^(?!.*\.tpl).+\.html$

Demo:

https://regex101.com/r/a0fl4H/8

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
0

For regex, this should do it;

/.*?[^.tpl]\.html/

Working example

Edit: This first solution needs improvement. As mentioned in the comments, this will provide false positives for test.t.html - as it matches any of the given characters (.tpl).

This is a working version using;

^(?!.*\.tpl).*.html

bar.html // matches
bar.tpl.html // doesn't match
test.t.html // matches
test.p.html // matches
test.z.html // matches
Tom
  • 4,257
  • 6
  • 33
  • 49
  • This would also match something like `a.t.html`. – M A Jan 30 '17 at 12:30
  • `[^.tpl]` doesn't mean anything except `.tpl`, a sequence of characters. – revo Jan 30 '17 at 12:41
  • @revo - I know, as I've mentioned in my answer. – Tom Jan 30 '17 at 12:42
  • Then you have to update the whole idea behind the answer I think as it doesn't answer the question. – revo Jan 30 '17 at 12:43
  • @revo - Why don't you enlighten us all with the correct answer, as I'm obviously not working it out for the OP quick enough to satisfy you. – Tom Jan 30 '17 at 12:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134381/discussion-between-thebluefox-and-revo). – Tom Jan 30 '17 at 12:48