perl regex extraction based on conditionA comprehensive regex for phone number validationConverting user input string to regular expressionRegEx match open tags except XHTML self-contained tagsExcept URL regexGreedy vs. Reluctant vs. Possessive QuantifiersWhy does modern Perl avoid UTF-8 by default?Perl regex field separatorsextracting specific URL based on a condition from a log file in perlperl regex to match string lengthJavascript engine fails while executing this regex if given long strings to test
What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?
What is this airplane that sits in front of Barringer High School in Newark, NJ?
I just entered the USA without passport control at Atlanta airport
First attempt at making linkedlist in c
First occurrence in the Sixers sequence
Why does a Force divides equally on a Multiple Support/Legs?
sudo passwd username keeps asking for the current password
Is there a polite way to ask about one's ethnicity?
Definition of 'vrit'
I found a password with hashcat but it doesn't work
Is declining an undergraduate award which causes me discomfort appropriate?
I have found ports on my Samsung smart tv running a display service. What can I do with it?
Justifying Affordable Bespoke Spaceships
In the US, can a former president run again?
What kind of chart is this?
Synaptic Static - when to roll the d6?
Does Snape have a bad hairstyle according to the wizarding world?
Time at 1G acceleration to travel 100 000 light years
King or Queen-Which piece is which?
What preparations would Hubble have needed to return in a Shuttle?
How is the idea of "girlfriend material" naturally expressed in Russian?
Titling: Unwanted Font Change in scrbook
How to sort human readable size
Do details of my undergraduate title matter?
perl regex extraction based on condition
A comprehensive regex for phone number validationConverting user input string to regular expressionRegEx match open tags except XHTML self-contained tagsExcept URL regexGreedy vs. Reluctant vs. Possessive QuantifiersWhy does modern Perl avoid UTF-8 by default?Perl regex field separatorsextracting specific URL based on a condition from a log file in perlperl regex to match string lengthJavascript engine fails while executing this regex if given long strings to test
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am working on a framework and I have to get some regex expressions but was stuck at this point.
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
In the above test results, I have to fetch the [Case-URL] and [Req-URL] for the Passed and Failed test cases . How do I get only the Case-URL and Req-URL for the passed results?
regex perl
add a comment |
I am working on a framework and I have to get some regex expressions but was stuck at this point.
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
In the above test results, I have to fetch the [Case-URL] and [Req-URL] for the Passed and Failed test cases . How do I get only the Case-URL and Req-URL for the passed results?
regex perl
add a comment |
I am working on a framework and I have to get some regex expressions but was stuck at this point.
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
In the above test results, I have to fetch the [Case-URL] and [Req-URL] for the Passed and Failed test cases . How do I get only the Case-URL and Req-URL for the passed results?
regex perl
I am working on a framework and I have to get some regex expressions but was stuck at this point.
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
In the above test results, I have to fetch the [Case-URL] and [Req-URL] for the Passed and Failed test cases . How do I get only the Case-URL and Req-URL for the passed results?
regex perl
regex perl
edited Mar 25 at 5:29
Cœur
20.5k10119162
20.5k10119162
asked Sep 13 '13 at 20:50
ankit dhebarankit dhebar
12
12
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Regexes are not terribly appropriate here. Instead, split your input into chunks which you parse individually:
use strict; use warnings; use feature 'say';
<DATA>; # discard first line;
# set record separator
local $/ = "__________________________________________________________n";
while (my $chunk = <DATA>)
my ($case, $req, $statusline) = split /n/, $chunk;
# possibly parse $case and $req further here
if ($statusline =~ /Passed/)
say for $case, $req;
__DATA__
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
Output would be:
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the$statuscontains/Passed. Your snippet does not contain this conditional!
– amon
Sep 13 '13 at 21:52
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
This will extract the failed cases. You can then extract Case-Url and Req-Url from $fifo[0] and $fifo[3] easily . Same can be done for Passed cases.
#!/usr/bin/perl
use strict;
use warnings;
my @fifo=('') x 7; # Initialize an empty array with size = 7 (Message Block Size)
open(FILE,"temp.txt");
while(<FILE>)
push(@fifo,$_); # Add element to the end of array making its size 6
shift @fifo; # Remove first element reverting its size back to 5
if($fifo[6]=~/Failed/) # Check if 7th line of block has Failed in it
print @fifo;
close(FILE);
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
The suitability of regex for this particular application aside, here is a regex that will capture the passed URLs:
([Case-Url] - .*)n+([Req-URL ] - (.*)n+*3Passed*3
I couldn't get this work with in Perl mode in regexplanet, but you can see it in action at Rubular here
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18795023%2fperl-regex-extraction-based-on-condition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Regexes are not terribly appropriate here. Instead, split your input into chunks which you parse individually:
use strict; use warnings; use feature 'say';
<DATA>; # discard first line;
# set record separator
local $/ = "__________________________________________________________n";
while (my $chunk = <DATA>)
my ($case, $req, $statusline) = split /n/, $chunk;
# possibly parse $case and $req further here
if ($statusline =~ /Passed/)
say for $case, $req;
__DATA__
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
Output would be:
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the$statuscontains/Passed. Your snippet does not contain this conditional!
– amon
Sep 13 '13 at 21:52
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
Regexes are not terribly appropriate here. Instead, split your input into chunks which you parse individually:
use strict; use warnings; use feature 'say';
<DATA>; # discard first line;
# set record separator
local $/ = "__________________________________________________________n";
while (my $chunk = <DATA>)
my ($case, $req, $statusline) = split /n/, $chunk;
# possibly parse $case and $req further here
if ($statusline =~ /Passed/)
say for $case, $req;
__DATA__
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
Output would be:
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the$statuscontains/Passed. Your snippet does not contain this conditional!
– amon
Sep 13 '13 at 21:52
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
Regexes are not terribly appropriate here. Instead, split your input into chunks which you parse individually:
use strict; use warnings; use feature 'say';
<DATA>; # discard first line;
# set record separator
local $/ = "__________________________________________________________n";
while (my $chunk = <DATA>)
my ($case, $req, $statusline) = split /n/, $chunk;
# possibly parse $case and $req further here
if ($statusline =~ /Passed/)
say for $case, $req;
__DATA__
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
Output would be:
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
Regexes are not terribly appropriate here. Instead, split your input into chunks which you parse individually:
use strict; use warnings; use feature 'say';
<DATA>; # discard first line;
# set record separator
local $/ = "__________________________________________________________n";
while (my $chunk = <DATA>)
my ($case, $req, $statusline) = split /n/, $chunk;
# possibly parse $case and $req further here
if ($statusline =~ /Passed/)
say for $case, $req;
__DATA__
Execution start time 09/13/2013 02:43:55 pm
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Passed***
__________________________________________________________
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
***Passed***
___________________________________________________________
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
***Failed***
Output would be:
[Case-Url] - www.google.com
[Req-URL ] - www.qtp.com
[Case-Url] - www.yahoo.com
[Req-URL ] - www.msn.com
answered Sep 13 '13 at 21:01
amonamon
53.1k272129
53.1k272129
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the$statuscontains/Passed. Your snippet does not contain this conditional!
– amon
Sep 13 '13 at 21:52
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the$statuscontains/Passed. Your snippet does not contain this conditional!
– amon
Sep 13 '13 at 21:52
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
Hi , Thanks for the reply. We are almost close but I have like 1000's of Case-Urls and Req-Url's and the above code displays all the lines from the input file which has these url's. I tried the following code ; while( my $temp = <FILE>) my($case,$req,$status) = split /n/,$temp; print "$casen"; But it displays all the lines and just not the first 2 case and req URL's ..
– ankit dhebar
Sep 13 '13 at 21:44
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the
$status contains /Passed. Your snippet does not contain this conditional!– amon
Sep 13 '13 at 21:52
@ankitdhebar My code works for me, I do not know what input you are using. Note that I only print out the URLs if the
$status contains /Passed. Your snippet does not contain this conditional!– amon
Sep 13 '13 at 21:52
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
thanks I will try the above code ..
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
This will extract the failed cases. You can then extract Case-Url and Req-Url from $fifo[0] and $fifo[3] easily . Same can be done for Passed cases.
#!/usr/bin/perl
use strict;
use warnings;
my @fifo=('') x 7; # Initialize an empty array with size = 7 (Message Block Size)
open(FILE,"temp.txt");
while(<FILE>)
push(@fifo,$_); # Add element to the end of array making its size 6
shift @fifo; # Remove first element reverting its size back to 5
if($fifo[6]=~/Failed/) # Check if 7th line of block has Failed in it
print @fifo;
close(FILE);
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
This will extract the failed cases. You can then extract Case-Url and Req-Url from $fifo[0] and $fifo[3] easily . Same can be done for Passed cases.
#!/usr/bin/perl
use strict;
use warnings;
my @fifo=('') x 7; # Initialize an empty array with size = 7 (Message Block Size)
open(FILE,"temp.txt");
while(<FILE>)
push(@fifo,$_); # Add element to the end of array making its size 6
shift @fifo; # Remove first element reverting its size back to 5
if($fifo[6]=~/Failed/) # Check if 7th line of block has Failed in it
print @fifo;
close(FILE);
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
This will extract the failed cases. You can then extract Case-Url and Req-Url from $fifo[0] and $fifo[3] easily . Same can be done for Passed cases.
#!/usr/bin/perl
use strict;
use warnings;
my @fifo=('') x 7; # Initialize an empty array with size = 7 (Message Block Size)
open(FILE,"temp.txt");
while(<FILE>)
push(@fifo,$_); # Add element to the end of array making its size 6
shift @fifo; # Remove first element reverting its size back to 5
if($fifo[6]=~/Failed/) # Check if 7th line of block has Failed in it
print @fifo;
close(FILE);
This will extract the failed cases. You can then extract Case-Url and Req-Url from $fifo[0] and $fifo[3] easily . Same can be done for Passed cases.
#!/usr/bin/perl
use strict;
use warnings;
my @fifo=('') x 7; # Initialize an empty array with size = 7 (Message Block Size)
open(FILE,"temp.txt");
while(<FILE>)
push(@fifo,$_); # Add element to the end of array making its size 6
shift @fifo; # Remove first element reverting its size back to 5
if($fifo[6]=~/Failed/) # Check if 7th line of block has Failed in it
print @fifo;
close(FILE);
answered Sep 13 '13 at 21:23
JeanJean
8,505175898
8,505175898
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
thank you .. I will try this code
– ankit dhebar
Sep 13 '13 at 22:13
add a comment |
The suitability of regex for this particular application aside, here is a regex that will capture the passed URLs:
([Case-Url] - .*)n+([Req-URL ] - (.*)n+*3Passed*3
I couldn't get this work with in Perl mode in regexplanet, but you can see it in action at Rubular here
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
add a comment |
The suitability of regex for this particular application aside, here is a regex that will capture the passed URLs:
([Case-Url] - .*)n+([Req-URL ] - (.*)n+*3Passed*3
I couldn't get this work with in Perl mode in regexplanet, but you can see it in action at Rubular here
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
add a comment |
The suitability of regex for this particular application aside, here is a regex that will capture the passed URLs:
([Case-Url] - .*)n+([Req-URL ] - (.*)n+*3Passed*3
I couldn't get this work with in Perl mode in regexplanet, but you can see it in action at Rubular here
The suitability of regex for this particular application aside, here is a regex that will capture the passed URLs:
([Case-Url] - .*)n+([Req-URL ] - (.*)n+*3Passed*3
I couldn't get this work with in Perl mode in regexplanet, but you can see it in action at Rubular here
answered Sep 13 '13 at 21:24
Peter AlfvinPeter Alfvin
23.1k65590
23.1k65590
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
add a comment |
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
thanks , I will try out this code ..
– ankit dhebar
Sep 13 '13 at 22:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18795023%2fperl-regex-extraction-based-on-condition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown