Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Take out date part of my field value

by Anonymous Monk
on Aug 24, 2005 at 14:37 UTC ( #486207=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to check if a field value has a date in the first part of the value and if it does then delete that part of the value:
(08/04/05) Information here etc...
To look like this:
Information here etc...
My attempt is not working. Please advise.
if($field =~ /d2\/d2\/d2/) { s/1//; }

Replies are listed 'Best First'.
Re: Take out date part of my field value
by socketdave (Curate) on Aug 24, 2005 at 14:45 UTC
    $field =~ s/\(\d{2}\/\d{2}\/\d{2}\)//;
    This will strip out the parentheses and the date. You were on the right track, but regex quantifiers (other than *, + and ?) use {}.

    Hope this helps.

      ++ the only thing I would change is the delimitter ... then no need to escape the slash.

      $field =~ s#\(\d{2}/\d{2}/\d{2}\)##;
Re: Take out date part of my field value
by pbeckingham (Parson) on Aug 24, 2005 at 14:41 UTC

    Simply substitute nothing for a pattern that matches your date. You may need to modify the pattern, and you probably should check out some of the excellent pages on regular expressions.

    $field =~ s/^\(\d\d\/\d\d\/\d\d\)\s+//;

    pbeckingham - typist, perishable vertebrate.
Re: Take out date part of my field value
by davidrw (Prior) on Aug 24, 2005 at 14:53 UTC
    slight variation the above for legibility (avoids having to escape the slashes):
    $field =~ s#^\(\d{2}/\d{2}/\d{2}\)\s+##;
Re: Take out date part of my field value
by punkish (Priest) on Aug 24, 2005 at 17:03 UTC
    d2 # matches the letter 'd' followed by the number '2' # not what you want d{2} # matches the letter 'd' at least and at most 2 times # this is what you want s/1//; # replaces the number '1' with nothing # not what you want s/$1// # does what you want

    when small people start casting long shadows, it is time to go to bed
Re: Take out date part of my field value
by sapnac (Beadle) on Aug 24, 2005 at 20:29 UTC
    Try this; $field =~ s/\d+\/\d+\/\d+//g; Hope it helps!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://486207]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-01-24 10:06 GMT
Find Nodes?
    Voting Booth?