How do I make a perl regular expresion fail in the code block?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I've got a screw I'm trying to nail in with perl and so far this is what I've got so far.



perl -ne '/(.+).(.+)((.+))(.+)(?{print "match" if  ( $1 > 9 || ( $1 == 9 && $2 > 1 ) || ($1 == 9 && $2 == 1 && $3 > 7 ) || $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22 ) })/' versions


versions:



9.1(7)23
9.1(7)22
8.1(7)22
7.2(33)24
55


it will print "match" if the version in the file is > than 9.1(7)23, which is good.



But I want the regexp to succeed, not just print "match". How do I translate the stuff inside the code block to an actual response. I've tried quite a few iterations with *ACCEPT|*FAIL but nothing has worked so far.










share|improve this question























  • Maybe using (??{}) instead of (?{}): /(.+).(.+)((.+))(.+)(??{ your_condition ? "" : "(*FAIL)"})/ ? I mean, this is OK if you are writing some quick one-liner for a one time job; but if this is supposed to be maintainable, production code, then don't try to do this with just a regex of course ;)

    – Dada
    Nov 16 '18 at 19:01













  • (peharps "(*ACCEPT)" instead of "". Both work, and I have no opinion on which is "better". ACCEPT is more explicit I guess; but since you are writing something not readable at all, does it really matter?)

    – Dada
    Nov 16 '18 at 19:12











  • @dada yeah, it's gotta be a one liner. I'm injecting into some version matching thing into some script to help a network guy out using their own tools. But that totally worked, thanks a lot you want to make it a legit answer to get credit?

    – Peter Turner
    Nov 16 '18 at 19:13




















1















I've got a screw I'm trying to nail in with perl and so far this is what I've got so far.



perl -ne '/(.+).(.+)((.+))(.+)(?{print "match" if  ( $1 > 9 || ( $1 == 9 && $2 > 1 ) || ($1 == 9 && $2 == 1 && $3 > 7 ) || $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22 ) })/' versions


versions:



9.1(7)23
9.1(7)22
8.1(7)22
7.2(33)24
55


it will print "match" if the version in the file is > than 9.1(7)23, which is good.



But I want the regexp to succeed, not just print "match". How do I translate the stuff inside the code block to an actual response. I've tried quite a few iterations with *ACCEPT|*FAIL but nothing has worked so far.










share|improve this question























  • Maybe using (??{}) instead of (?{}): /(.+).(.+)((.+))(.+)(??{ your_condition ? "" : "(*FAIL)"})/ ? I mean, this is OK if you are writing some quick one-liner for a one time job; but if this is supposed to be maintainable, production code, then don't try to do this with just a regex of course ;)

    – Dada
    Nov 16 '18 at 19:01













  • (peharps "(*ACCEPT)" instead of "". Both work, and I have no opinion on which is "better". ACCEPT is more explicit I guess; but since you are writing something not readable at all, does it really matter?)

    – Dada
    Nov 16 '18 at 19:12











  • @dada yeah, it's gotta be a one liner. I'm injecting into some version matching thing into some script to help a network guy out using their own tools. But that totally worked, thanks a lot you want to make it a legit answer to get credit?

    – Peter Turner
    Nov 16 '18 at 19:13
















1












1








1








I've got a screw I'm trying to nail in with perl and so far this is what I've got so far.



perl -ne '/(.+).(.+)((.+))(.+)(?{print "match" if  ( $1 > 9 || ( $1 == 9 && $2 > 1 ) || ($1 == 9 && $2 == 1 && $3 > 7 ) || $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22 ) })/' versions


versions:



9.1(7)23
9.1(7)22
8.1(7)22
7.2(33)24
55


it will print "match" if the version in the file is > than 9.1(7)23, which is good.



But I want the regexp to succeed, not just print "match". How do I translate the stuff inside the code block to an actual response. I've tried quite a few iterations with *ACCEPT|*FAIL but nothing has worked so far.










share|improve this question














I've got a screw I'm trying to nail in with perl and so far this is what I've got so far.



perl -ne '/(.+).(.+)((.+))(.+)(?{print "match" if  ( $1 > 9 || ( $1 == 9 && $2 > 1 ) || ($1 == 9 && $2 == 1 && $3 > 7 ) || $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22 ) })/' versions


versions:



9.1(7)23
9.1(7)22
8.1(7)22
7.2(33)24
55


it will print "match" if the version in the file is > than 9.1(7)23, which is good.



But I want the regexp to succeed, not just print "match". How do I translate the stuff inside the code block to an actual response. I've tried quite a few iterations with *ACCEPT|*FAIL but nothing has worked so far.







perl pcre






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 18:41









Peter TurnerPeter Turner

5,022855102




5,022855102













  • Maybe using (??{}) instead of (?{}): /(.+).(.+)((.+))(.+)(??{ your_condition ? "" : "(*FAIL)"})/ ? I mean, this is OK if you are writing some quick one-liner for a one time job; but if this is supposed to be maintainable, production code, then don't try to do this with just a regex of course ;)

    – Dada
    Nov 16 '18 at 19:01













  • (peharps "(*ACCEPT)" instead of "". Both work, and I have no opinion on which is "better". ACCEPT is more explicit I guess; but since you are writing something not readable at all, does it really matter?)

    – Dada
    Nov 16 '18 at 19:12











  • @dada yeah, it's gotta be a one liner. I'm injecting into some version matching thing into some script to help a network guy out using their own tools. But that totally worked, thanks a lot you want to make it a legit answer to get credit?

    – Peter Turner
    Nov 16 '18 at 19:13





















  • Maybe using (??{}) instead of (?{}): /(.+).(.+)((.+))(.+)(??{ your_condition ? "" : "(*FAIL)"})/ ? I mean, this is OK if you are writing some quick one-liner for a one time job; but if this is supposed to be maintainable, production code, then don't try to do this with just a regex of course ;)

    – Dada
    Nov 16 '18 at 19:01













  • (peharps "(*ACCEPT)" instead of "". Both work, and I have no opinion on which is "better". ACCEPT is more explicit I guess; but since you are writing something not readable at all, does it really matter?)

    – Dada
    Nov 16 '18 at 19:12











  • @dada yeah, it's gotta be a one liner. I'm injecting into some version matching thing into some script to help a network guy out using their own tools. But that totally worked, thanks a lot you want to make it a legit answer to get credit?

    – Peter Turner
    Nov 16 '18 at 19:13



















Maybe using (??{}) instead of (?{}): /(.+).(.+)((.+))(.+)(??{ your_condition ? "" : "(*FAIL)"})/ ? I mean, this is OK if you are writing some quick one-liner for a one time job; but if this is supposed to be maintainable, production code, then don't try to do this with just a regex of course ;)

– Dada
Nov 16 '18 at 19:01







Maybe using (??{}) instead of (?{}): /(.+).(.+)((.+))(.+)(??{ your_condition ? "" : "(*FAIL)"})/ ? I mean, this is OK if you are writing some quick one-liner for a one time job; but if this is supposed to be maintainable, production code, then don't try to do this with just a regex of course ;)

– Dada
Nov 16 '18 at 19:01















(peharps "(*ACCEPT)" instead of "". Both work, and I have no opinion on which is "better". ACCEPT is more explicit I guess; but since you are writing something not readable at all, does it really matter?)

– Dada
Nov 16 '18 at 19:12





(peharps "(*ACCEPT)" instead of "". Both work, and I have no opinion on which is "better". ACCEPT is more explicit I guess; but since you are writing something not readable at all, does it really matter?)

– Dada
Nov 16 '18 at 19:12













@dada yeah, it's gotta be a one liner. I'm injecting into some version matching thing into some script to help a network guy out using their own tools. But that totally worked, thanks a lot you want to make it a legit answer to get credit?

– Peter Turner
Nov 16 '18 at 19:13







@dada yeah, it's gotta be a one liner. I'm injecting into some version matching thing into some script to help a network guy out using their own tools. But that totally worked, thanks a lot you want to make it a legit answer to get credit?

– Peter Turner
Nov 16 '18 at 19:13














1 Answer
1






active

oldest

votes


















4














First of all, the regex does succeed. But it does so whether the condition is true or not. I think you're actually asking for it to fail when the condition is false. For that, you want



(?(?{ condition })(*ACCEPT)|(*FAIL))


or just



(?(?{ !condition })(*FAIL))


Fixed:



perl -nle'
print "$_: match"
if /
^(.+).(.+)((.+))(.+)z
(?(?{
!( $1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
)
})(*FAIL))
/x;
' versions


A far better approach is to do the check outside of the pattern.



perl -nle'
print "$_: match"
if /^(.+).(.+)((.+))(.+)z/
&& (
$1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
);
' versions





share|improve this answer


























  • from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

    – Nahuel Fouilleul
    Nov 19 '18 at 15:50











  • @NahuelFouilleul, No idea what it does, but it's not needed

    – ikegami
    Nov 19 '18 at 19:28












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343632%2fhow-do-i-make-a-perl-regular-expresion-fail-in-the-code-block%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














First of all, the regex does succeed. But it does so whether the condition is true or not. I think you're actually asking for it to fail when the condition is false. For that, you want



(?(?{ condition })(*ACCEPT)|(*FAIL))


or just



(?(?{ !condition })(*FAIL))


Fixed:



perl -nle'
print "$_: match"
if /
^(.+).(.+)((.+))(.+)z
(?(?{
!( $1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
)
})(*FAIL))
/x;
' versions


A far better approach is to do the check outside of the pattern.



perl -nle'
print "$_: match"
if /^(.+).(.+)((.+))(.+)z/
&& (
$1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
);
' versions





share|improve this answer


























  • from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

    – Nahuel Fouilleul
    Nov 19 '18 at 15:50











  • @NahuelFouilleul, No idea what it does, but it's not needed

    – ikegami
    Nov 19 '18 at 19:28
















4














First of all, the regex does succeed. But it does so whether the condition is true or not. I think you're actually asking for it to fail when the condition is false. For that, you want



(?(?{ condition })(*ACCEPT)|(*FAIL))


or just



(?(?{ !condition })(*FAIL))


Fixed:



perl -nle'
print "$_: match"
if /
^(.+).(.+)((.+))(.+)z
(?(?{
!( $1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
)
})(*FAIL))
/x;
' versions


A far better approach is to do the check outside of the pattern.



perl -nle'
print "$_: match"
if /^(.+).(.+)((.+))(.+)z/
&& (
$1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
);
' versions





share|improve this answer


























  • from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

    – Nahuel Fouilleul
    Nov 19 '18 at 15:50











  • @NahuelFouilleul, No idea what it does, but it's not needed

    – ikegami
    Nov 19 '18 at 19:28














4












4








4







First of all, the regex does succeed. But it does so whether the condition is true or not. I think you're actually asking for it to fail when the condition is false. For that, you want



(?(?{ condition })(*ACCEPT)|(*FAIL))


or just



(?(?{ !condition })(*FAIL))


Fixed:



perl -nle'
print "$_: match"
if /
^(.+).(.+)((.+))(.+)z
(?(?{
!( $1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
)
})(*FAIL))
/x;
' versions


A far better approach is to do the check outside of the pattern.



perl -nle'
print "$_: match"
if /^(.+).(.+)((.+))(.+)z/
&& (
$1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
);
' versions





share|improve this answer















First of all, the regex does succeed. But it does so whether the condition is true or not. I think you're actually asking for it to fail when the condition is false. For that, you want



(?(?{ condition })(*ACCEPT)|(*FAIL))


or just



(?(?{ !condition })(*FAIL))


Fixed:



perl -nle'
print "$_: match"
if /
^(.+).(.+)((.+))(.+)z
(?(?{
!( $1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
)
})(*FAIL))
/x;
' versions


A far better approach is to do the check outside of the pattern.



perl -nle'
print "$_: match"
if /^(.+).(.+)((.+))(.+)z/
&& (
$1 > 9
|| $1 == 9 && $2 > 1
|| $1 == 9 && $2 == 1 && $3 > 7
|| $1 == 9 && $2 == 1 && $3 == 7 && $4 > 22
);
' versions






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 21:54

























answered Nov 16 '18 at 19:49









ikegamiikegami

268k11181407




268k11181407













  • from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

    – Nahuel Fouilleul
    Nov 19 '18 at 15:50











  • @NahuelFouilleul, No idea what it does, but it's not needed

    – ikegami
    Nov 19 '18 at 19:28



















  • from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

    – Nahuel Fouilleul
    Nov 19 '18 at 15:50











  • @NahuelFouilleul, No idea what it does, but it's not needed

    – ikegami
    Nov 19 '18 at 19:28

















from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

– Nahuel Fouilleul
Nov 19 '18 at 15:50





from my undrstanding (*FAIL) will just force to backtrack maybe (*SKIP)(*FAIL)

– Nahuel Fouilleul
Nov 19 '18 at 15:50













@NahuelFouilleul, No idea what it does, but it's not needed

– ikegami
Nov 19 '18 at 19:28





@NahuelFouilleul, No idea what it does, but it's not needed

– ikegami
Nov 19 '18 at 19:28




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343632%2fhow-do-i-make-a-perl-regular-expresion-fail-in-the-code-block%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Bressuire

Vorschmack

Quarantine