A single regex to match anything with ".aac" or ".mp3" at the end ?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Tried ".*/.[\baac\b\bmp3\b]$" but no go. Tried many variations of this?
By using that regex you are asking machine for a string that consits any number characters, followed by a single character from a set "ac\bmp3" and has newline at the end.
By the way, where do you want to use regex?
This looks for any file that ends with a or m in 3rd from last character, a or p in 2nd from last and c or 3 in last. It will match the files you want but might match other oddities if they are there (e.g. aa3, mpc, apc...)
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Originally Posted by colucix
Why not simply...?
find . -name \*.mp3 -o -name \*.aac
Again, the sordid details. Add to these details that I'd also like very much to learn more about the power of regular expressions.
My regex is in a php script, so while the other solution is very cool and creative "[am][ap][c3]", I need to be able to insert new file extensions by variable into my regex string. In other words, I need to be able to insert "avi" into this regex pattern string, and then use it in my find command to look for new file types. I'm pretty sure this is possible, and for various reasons I must use find and regexes.
Because different tools (including the shell) interpret the characters seen. The shell treats parentheses as "grouping" of commands and the vertical bar as a "pipe". It would therefore think you were attempting to pipe command aac into command mp3 and would attempt to do that BEFORE the rest of the line due to the grouping. Escaping and quoting is one of the most maddening things you'll deal with in scripting.
There is a command line I've used that actually quotes escapes and escapes quotes to work correctly. It seems to be nonsensical to do that but on a command line where you're in a shell and piping things into awk and/or grep it sometimes is necessary to do things like this to be sure one thing treats it literally and passes it on that way to something else that you want to interpret it.