String Search containing a '/' character

B

Bumble

Basically I have a date, say 02/04, in a text file. I need to find that so
i've got

if ($line=~m/\d\d??\d\d/)

to find the 2 lots of digits (the date and month) but I can't work out how I
add the / in there (in place of the ??) I've tried a few things but nothing
is working?
 
G

gnari

Bumble said:
Basically I have a date, say 02/04, in a text file. I need to find that so
i've got

if ($line=~m/\d\d??\d\d/)

to find the 2 lots of digits (the date and month) but I can't work out how I
add the / in there (in place of the ??) I've tried a few things but nothing
is working?

but have you tried reading the docs ?
perldoc perlre

gnari
 
A

Anno Siegel

Bumble said:
Basically I have a date, say 02/04, in a text file. I need to find that so
i've got

if ($line=~m/\d\d??\d\d/)

to find the 2 lots of digits (the date and month) but I can't work out how I
add the / in there (in place of the ??) I've tried a few things but nothing
is working?

Did "a few things" include escaping the "/" with a backslash? That isn't
the best method, but it is certainly something to try, and it works.
It's better to use an alternative delimiter instead of "/". So both
"/\d\d\/\d\d/" and "m!\d\d/\d\d!" should work.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top