in reply to @ ergular expression

What specifically did you try that failed? "does not work" can mean a lot of different things. See I know what I mean. Why don't you? and How do I post a question effectively?. If you post code showing us what didn't work, we can do a lot more in showing you what will. I am also unsure what you mean by "using anchor tag".

Assuming you have a variable $str that contains 03:20:21 - PID: 11500 - kernel bitness: 64, you can output the desired string with the line:

print $str =~ /kernel bitness:\s(\d*)/;

If this does not work for you, post code and sample input and output so we can refine the approach. See perlretut for more guidance in constructing regular expressions.

Replies are listed 'Best First'.
Re^2: @ ergular expression
by siddheshsawant (Sexton) on May 13, 2010 at 20:27 UTC

    Hi, I tried to implement what you have asked me to do but it;s printing nothing

    The Part of code is as follows

    #!/usr/bin/perl -w use strict; #The below variable $mystring is used for some other example my $mystring = "http://192.168.153.238/nightly_results/2009_12_02/log_ +lcla114.lss.emc.com_64___TestSuitePPAll_TestSuitePPSym_TestSuitePPper +f_TestSuitePPTx_TestSuitePPConCurrent_Prod_SymmSLV_AIX__3_15.html"; my $sample_sentence = "The kernel bitness: 64"; # ----------- The code corresponds to $mystring ------------# if($mystring =~ m/nightly_results(.*?)(.html)/) { my $web_link= "/nightly_db".$1; print $web_link; } if($mystring =~ m!([^/]+)$!){ my $file=$1; print "field= $file\n"; } #-----------Code ends corresponds to $myString -------------# #----------------- code corresponds to $sample_sentence -----------# print $sample_sentence =~ /kernel bitness:\s(\d*)/; #------------- COde ends here b--------------------#

    I was trying to implement $mystring code in the case $sample_sentence as well.But I could not able to display the Appropriate output

    Can you do one favor on me in order to extract the desired output ? Because the solution you asked me to implement is not working properly

      This is why question content and formatting is so important: my expression was built for

      03:20:21 - PID: 11500 - kernel bitness: 64

      but the term you are trying to match is

      The kernel bitness:   64

      My expression failed because your real input contained more spaces. The following modified version matches the new provided input:

      print $str =~ /kernel bitness:\s*(\d*)/;

      By adding the * modifier to \s it will now match any amount of white space. Again, see perlretut for more info.

        Thanks a lot....