views:

133

answers:

3
+1  Q: 

Regex hackery

A: 

"I used the colon because no desktop OS would allow that in a filename, so I am safe."

Nice try. It is allowed under GNU/Linux.

More importantly, you have only given examples. You have not described what the regex is intended to do. You also have obviously pointless constructs, like (?: ), which could just be a single space.

Finally, it's unclear what role the colon actually plays, as it's not in your replacement text. Perhaps it would help if you told us what language you're using.

Matthew Flaschen
It's obviously intended to download everything off of the Pirate Bay.
Eric
@Eric +1 for pointing that out. Some of us have never used it.
Sinan Ünür
Hi! I thought that the question was clear enough? Ahnyways, the regex is suposed t transform lines like "1. 10.Things.I.Hate.About.You[1999]DvDrip[Eng]-Ray 699.68 MB" into "10.Things.I.Hate.About.You[1999]DvDrip[Eng]-Ray,699.68" and I was asking for the best kind of regex to do that - something like what Sinan did..
PoorLuzer
+2  A: 

I use The Regex Coach.

Andrew Hare
+2  A: 

In Perl:

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

while ( <DATA> ) {
    no warnings 'uninitialized';
    next unless /^[^.]+\. (.+?) (?:(\d+) )?(\d+(?:.\d+)?) MB$/ ;
    print "$1,$2$3\n";
}

__DATA__
1. 10.Things.I.Hate.About.You[1999]DvDrip[Eng]-Ray 699.68 MB
2. 100.Feet.2008.DvDRip-FxM 701.14 MB
3. 11 - 14 1 286.22 MB
4. 13_going_on_30(2004)[Brizzly] 700.23 MB
...
1 523. Waz 699.93 MB
1 524. We.Own.the.Night[2007]DvDrip[Eng]-Ray 700.87 MB
1 525. Webs [2003]DVDRip[Xvid AC3[5.1]-RoCK&BlueLadyRG 1 347.70 MB

Output:

C:\Temp> zcx
10.Things.I.Hate.About.You[1999]DvDrip[Eng]-Ray,699.68
100.Feet.2008.DvDRip-FxM,701.14
11 - 14,1286.22
13_going_on_30(2004)[Brizzly],700.23
Waz,699.93
We.Own.the.Night[2007]DvDrip[Eng]-Ray,700.87
Webs [2003]DVDRip[Xvid AC3[5.1]-RoCK&BlueLadyRG,1347.70
Sinan Ünür