pierrefelipe
pierrefelipe

Reputation: 71

Regex working, but still not working

In order to save time I made this little script to check sport results for me: However Padre complains about syntax error at line 7 near "+>"

When testing it on various regex-sites it works splendid. What am I missing?

#!/usr/bin/perl

use LWP::Simple;
my $url = "https://svenskaspel.se/?pageid=/resultat/topptipset";
my $content = get($url);

$content = (\d{1}.+/-/.+).*?([/1X2/]{1});
print ("Match $1        Resultat: $2");

Cheers

Upvotes: 1

Views: 61

Answers (1)

collapsar
collapsar

Reputation: 17238

After inspecting the provided link i suspect you want this one:

# sample line     4 AZ Alkmaar - PSV Eindhoven        2  2 - 4
#                  |\_________________________/\______/|\/\___/
#                  |              |               |    / \   |
#                  |              |               |   /   \  |
#                 (1)            (2)             (3) (4) (5)(6)

     $content =~ /(\d+.+)[ ]+([1X2])[ ]+\d+\s*[-]\*\d+/;

# explanation     ^   ^  ^    ^     ^   ^
#                (1) (2)(3)  (4)   (5) (6)
#                 |   |  |    |     |   +---- context: matching this portion together with (3)-(5) limits the greedy match of the team names.
#                 |   |  |    |     +-------- context
#                 |   |  |    +-------------- result code
#                 |   |  +------------------- context (no trailing spaces in the capture group representing teams)
#                 |   +---------------------- teams w/o leading and trailing spaces
#                 +-------------------------- id of the tournament match

Upvotes: 1

Related Questions