Search code examples
javascriptjavaregexregexp-replacepentaho-data-integration

Finding file name with variables in between


Having a hard time with Regex. What would be the regex for finding a file name with variable in between them? For eg:

File name : DON_2010_JOE_1222022.txt

In the above file name the words DON, JOE and the format .txt will remain constant. Rest numbers might change for every file. There could be characters as well instead of numbers in those two places. What im looking for is basically something like DON_*_JOE_*.txt with * being whatever it could be.

Can someone please help me with this?

I tried DON_*_JOE_*.txt and obviously it did not work.


Solution

  • In JavaScript:
    "DON_2010_JOE_1222022.txt".match(/DON_.+_JOE_.+\.txt/)

    whatever it could be

    It is .+ except new lines.