-2

Hey I have a list of files

  • B123245.xml
  • B123245-ext.xml
  • 1234W01.xml
  • 1234W01-ext.xml

Now I need a regular expression filter only the files without -ext in the name.

I tried already this ^.+(?!-ext)\.xml$ but it is not working.

What am I doing wrong?

dj_thossi
  • 774
  • 1
  • 9
  • 18

2 Answers2

2

Not sure about your exact needs, but if you want to exclude those file where "-ext" is right before the xml extension I think you could use:

^.+(?<!-ext)\.xml$

See the demo

  • ^ - Start string anchor.
  • .+ - 1+ character apart from newline.
  • (?<!-ext) - A negative lookbehind to assert position isn't preceded by "-ext".
  • \.xml - Match a literal dot and "xml".
  • $ - End string anchor.
JvdV
  • 70,606
  • 8
  • 39
  • 70
0

With the help of user 'The fourth bird' I found out the correct structure.

Here is the correct result

^(?!.*-ext).+\.xml$
dj_thossi
  • 774
  • 1
  • 9
  • 18