Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
and here's the Perl regex I've been using, and that's been failing..Formal Definition: The value type is defined by the following notation: dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week) dur-date = dur-day [dur-time] dur-time = "T" (dur-hour / dur-minute / dur-second) dur-week = 1*DIGIT "W" dur-hour = 1*DIGIT "H" [dur-minute] dur-minute = 1*DIGIT "M" [dur-second] dur-second = 1*DIGIT "S" dur-day = 1*DIGIT "D"
this fails even on simple duration strings (eg "P1D" ). thanks, in advance, for the suggestions.my @temp = $str =~ m{ ([\+\-])? (?# Sign) (P) (?# 'P' for period? This is our magic character) (?: (?:(\d+)Y)? (?# Years) (?:(\d+)M)? (?# Months) (?:(\d+)W)? (?# Weeks) (?:(\d+)D)? (?# Days) )? (?:T (?# Time prefix) (?:(\d+)H)? (?# Hours) (?:(\d+)M)? (?# Minutes) (?:(\d+)S)? (?# Seconds) )? }x;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex - parsing a string with many optional fields
by matija (Priest) on Feb 25, 2004 at 14:34 UTC | |
|
Re: regex - parsing a string with many optional fields
by dragonchild (Archbishop) on Feb 25, 2004 at 14:31 UTC | |
|
Re: regex - parsing a string with many optional fields
by Fletch (Bishop) on Feb 25, 2004 at 14:32 UTC | |
|
Re: regex - parsing a string with many optional fields
by delirium (Chaplain) on Feb 25, 2004 at 14:26 UTC | |
by dragonchild (Archbishop) on Feb 25, 2004 at 14:30 UTC |