-2

I have a database that has a list of servers that I am downloading data from. I want to add a column that has a regex pattern so that my program can only download files that match this pattern.

Having never learnt regex before, I am in need of a little help.

I currently want the regex to match any files that have a extension of .edi. How would I go about this?

How about matching the filename exact (as some customers may want)? For instances, the file is always going to be called salesorder.txt.

What if the customer doesn't want to match on any file, and wants us to pull all files? Is there a regex that will grab everything.. or is a blank regex the same as that?

Thanks!

Lock
  • 5,422
  • 14
  • 66
  • 113
  • * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Dec 10 '12 at 04:33

2 Answers2

1

For .edi extension files: .*\.edi$

For fixed filename "salesroder.txt" ^salesorder\.txt$

Billy Chan
  • 24,625
  • 4
  • 52
  • 68
  • Thanks. I have the exact above regex in a string, but I am getting the following error: [PHP Warning] preg_match(): No ending delimiter '^' found. I am using the following code: if ( ! preg_match($job["file_filter"], $tmp["file"]) ) continue; – Lock Dec 10 '12 at 12:03
  • Putting slashes at the start at end appears to have fixed the issue. – Lock Dec 10 '12 at 12:07
  • Did you use "//" to wrap regex? Like this: $pattern = '/^def/'; ref: http://php.net/manual/en/function.preg-match.php. Okay, I saw you fixed it. – Billy Chan Dec 10 '12 at 12:08
1

To match anything

.*

the dot means "whichever character" and the star means "any amount of them" And @Billy chan answered the rest

fersarr
  • 3,399
  • 3
  • 28
  • 35