PDA

View Full Version : Trying to find the right pattern


recluse
06-11-2002, 04:06 AM
I've been struggling with this one for an hour and I guess it looks like I'm not going to get it.

I have multiple playlist files listed in a menu, and I'm trying to find a regex that will match all of the m3u files. Maybe I'm just trying too hard.

Example of menu listings:

[exec] (incubus-make_yourself.m3u) {xmms -p ~/audio/incubus-make_yourself.m3u}
[exec] (papa_roach-infest.m3u) {xmms -p ~/audio/papa_roach-infest.m3u}
[exec] (tantric-tantric.m3u) {xmms -p ~/audio/tantric-tantric.m3u}
[exec] (bush-sixteen_stone.m3u) {xmms -p ~/audio/bush-sixteen_stone.m3u}

of course '[exec]' is the start of every line, in case the fomatting is f00ked.:p

iDxMan
06-11-2002, 09:39 AM
This seemed to work in a quick test.


/\{xmms\s-p\s(.*)\}/


Will it always have "xmms -p " in it?

-r

inkedmn
06-11-2002, 12:28 PM
it's because you're missing keyword "radiohead" :)

recluse
06-11-2002, 02:53 PM
Thanks, iDxMan. yah they should all have the xmms part in them. I'll give it a try when I get home.

Strike
06-11-2002, 03:41 PM
"^\[exec\]\s+\(\w+\.m3u)\s+\(xmms -p\s+~\/audio\/\w+\.m3u\)$"

That looks like it will do it
matches anything that starts with "[exec]", has some space, then a (, then some nonwhitespace characters, then .m3u and a ), then some space, then another (, with "xmms -p" after it, then some space, then "~/audio/", then some nonwhitespace chars, then .m3u, and finally a ) at the end of the line

Strike
06-11-2002, 03:42 PM
ack, sorry, replace those () in the second part with {}s - I wasn't paying attention :)

l2kashe
08-21-2002, 04:50 PM
you could also split the lines

($drop,$file) = split(/(/, $line);
($file,$drop) = split(/)/,$file);

$file will now be whats between the '(' ')'s

or if you want you could whack whitespaces, substr the line and then split on the closing parentheses.

I.e
$offset = "8"; # [exec] ( == 8 chars;
$line =~ s/^\s+//;
$len = (length($line) - $offset);
$tmp = substr($line,$offset,$len);

$file = (split(/)/,$tmp)[0];

Or even

$line =~ s/^\s+//;
$line =~ s/(\(|\))/ /g;
$file_name = (split(/\s+/,$line))[1];

just some other ways to do it.