Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: word with some number in between

by Anonymous Monk
on Jun 29, 2013 at 10:59 UTC ( #1041446=note: print w/ replies, xml ) Need Help??


in reply to Re: word with some number in between
in thread word with some number in between

hey i did this , but there is some issue with the command , the first $ is not a part of regex as per perl . with this regex what i tried doing is that some $ before num and some $ after it . please tell what is the mistake

if ($array_A[$i] =~ /^$+[0-9]+$/)


Comment on Re^2: word with some number in between
Download Code
Re^3: word with some number in between
by hippo (Vicar) on Jun 29, 2013 at 11:22 UTC

    The /^$+ part makes no sense. If you you just want to test for the presence of digits then a simple /[0-9]/ will work splendidly.

      Continuing hippo's advice, you should continue to the grep part next.

      Cheers, Sören

      (hooked on the Perl Programming language)

      but since /0-9/ can be anywhere in the word , not necessarily in beginning or end

        Precisely. eg.

        $ perl -e 'print "Matched.\n" if "foo8baz" =~ /[0-9]/;' Matched. $ perl -e 'print "Matched.\n" if "foobaz" =~ /[0-9]/;'
Re^3: word with some number in between
by ww (Bishop) on Jun 29, 2013 at 15:01 UTC
    " ... what i tried doing is that some $ before num and some $ after it "

    Do you, by any chance, mean you tried to deal with data that included a "$" sign... such as:  abc12$ or  $98abc or  $$zyx5abc or something similar?

    If so, you'll have to escape the "$" sign (with a preceding backslash, "\") in your regex.

    perl -E "my $s='$abc123'; if ($s =~ /\$/ ) { say 'Found a dollar-sign';}

    which outputs:

    Found a dollar-sign

    Otherwise, (slightly oversimplified), the regex engine uses the "$" sign is only to mark an EOL.

    Updated by quoting a possibly mis-understood part of OP's latest question.


    If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041446]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2015-07-04 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls