-3

Suppose I have some files

\\foo\bar\12345.xml
\\foo\bar\23456.xml
\\foo\bar\12hellothere.xml
\\foo\bar\34youpeople.xml

The first two are characterised by only having numbers in the file name (not including the extension). The last two do not consist entirely of numbers.

The directory names can contain whitespace and numbers.

Does anyone have a regular expression which matches the last two files, and not the first two?

I'm implementing this in Java if that is at all relevant.

Essentially I think it boils down to not .*\\\d+.xml but I don't know how to specify the not.

P45 Imminent
  • 8,319
  • 4
  • 35
  • 78

4 Answers4

0

Only for file name: [0-9][0-9][a-z]+

File name + .xml: [0-9][0-9][a-z]+.xml

Fie name but with more than two numbers on the beginning: [0-9]+[a-z]+

There is a site where you can test your regular expressions here: regexp

pokemzok
  • 1,659
  • 1
  • 19
  • 29
0

The best regular expression for that would probably be:

(only for filename, for clarity)

\w*\D\w*.xml

NOTE: This considering you consider anything that's not a number as valid, like 10 10.xml

EDIT: In case you want it to be a letter:

\w*[a-zA-Z]\w*.xml

dquijada
  • 1,697
  • 3
  • 14
  • 19
0

Try this

    String[] s = {
        "\\\\foo\\bar\\12345.xml",
        "\\\\foo\\bar\\23456.xml",
        "\\\\foo\\bar\\12hellothere.xml",
        "\\\\foo\\bar\\34youpeople.xml",
        "34youpeople.xml",
    };
    for (String e : s)
        System.out.println(e + " -> " + e.matches("(.*\\\\)?\\d+[a-zA-Z]+\\.xml"));

result:

\\foo\bar\12345.xml -> false
\\foo\bar\23456.xml -> false
\\foo\bar\12hellothere.xml -> true
\\foo\bar\34youpeople.xml -> true
34youpeople.xml -> true
0

This

^((?!(.*\\\d+.xml)).)*$

is one way.

Inspired from Regular expression to match a line that doesn't contain a word?

Community
  • 1
  • 1
P45 Imminent
  • 8,319
  • 4
  • 35
  • 78