Regular expression for a valid filename without extension

后端 未结 2 770
终归单人心
终归单人心 2021-01-14 23:57

I need a regular expression pattern to check a string for alphanumeric(a-zA-z0-9) and also can contain underscore, hypen and dot this will be a file name so i dont want othe

相关标签:
2条回答
  • 2021-01-14 23:59

    Check out "Character Classes" in the docs. Basically, [a-zA-Z0-9_\-\.]+ should do it. If you put that in a string, be sure to escape the backslashes.

    0 讨论(0)
  • 2021-01-15 00:21

    Re:

    I need a regular expression pattern to check a string for alphanumeric(a-zA-z0-9) and also can contain underscore, hypen and dot

    The pattern will be "[_a-zA-Z0-9\\-\\.]+"

    Note the double-backslashes, since this is first interpreted as a Java string and the backslashes need to stay intact for the regex.

    0 讨论(0)
提交回复
热议问题