delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

my input file consists of several lines in the format:
Resource Donation        March 7, 2009, 9:52        Avallach donated 150000 iron to the clan.
however, my output file simply consists of several lines of:
line doesn't match: Non-resource invalid date no words
Have I done something silly?


It's been a while since I had to do anything in perl, and I've been working in php and C++ in the meantime, so it's very possible I've done something stupid; however, I can't get my regex to report a match:
Code:
  1. if ($line =~ /(Resource Donation)(March\s\d,\s\d\d\d\d,\s\d\d:\d\d)(\w.+)/i) {
  2. #rest of program here
  3. } else {
  4.                print OUTPUT "line doesn't match: ";
  5.                 if ($line !~ /Resource Donation/) {
  6.                         print OUTPUT "Non-resource ";
  7.                 }
  8.                 if ($line !~ /(March\s\d,\s\d\d\d\d,\s\d\d:\d\d)/) {
  9.                         print OUTPUT "invalid date ";
  10.                 }
  11.                 if ($line !~ /(\w.+)/) {
  12.                         print OUTPUT "no words";
  13.                 }
  14.                 print OUTPUT "\n";
  15. }
Copy Code
my input file consists of several lines in the format:
Resource Donation        March 7, 2009, 9:52        Avallach donated 150000 iron to the clan.
however, my output file simply consists of several lines of:
line doesn't match: Non-resource invalid date no words
Have I done something silly?

TOP

Your regex:
Code:
  1. /(Resource Donation)(March\s\d,\s\d\d\d\d,\s\d\d:\d\d)(\w.+)/i
Copy Code
- does not have a space between "Donation" and "March";
- defined the hour-part of your regex as HH:MM while your example string is like this: H:MM;
- after the HH:MM, there's no space: \w does not encapsulate spaces;
That said, this ought to work:
Code:
  1. /(Resource\s+Donation)\s+(March\s+\d{1,2},\s+\d{4},\s+\d{1,2}:\d{2})\s+(.+)/i
Copy Code
Good luck!

TOP

Thanks; I still had issues after that but it turns out I was using "chomp" incorrectly >.> it works now

TOP


Originally Posted by yamikuronue
Thanks; I still had issues after that but it turns out I was using "chomp" incorrectly >.> it works now
Good to hear that, and you're welcome.



my input file consists of several lines in the format:
Resource Donation        March 7, 2009, 9:52        Avallach donated 150000 iron to the clan.
however, my output file simply consists of several lines of:
line doesn't match: Non-resource invalid date no words
Have I done something silly?

TOP

Back Forum