in reply to Re: Steps to get a substring from a string
in thread Steps to get a substring from a string

Hi Corion

How about the 2nd case,2) I have name=servername , i want to still capture the first part in a variable. In this your code will not work. we need to match a-zA-Z character after =

my $str='name=host.com' my ($match) =$string=~/=([a-zA-Z]+)/;
Update:

Updated the regex part as per CountZero's node Re^3: Steps to get a substring from a string


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^3: Steps to get a substring from a string
by CountZero (Bishop) on Jul 21, 2015 at 17:05 UTC
    According to RFC952 and RFC-1123, the hostname should only consists of the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). Spaces and underscores are not allowed!

    Update: added "and underscores"

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      ++CountZero

      Oh Sorry! Actually I considered only string part and written the script, I will update the same. Thank you CountZero


      All is well. I learn by answering your questions...