Regex matching with “(” in perl












1















I have tried the below code



my $line = "(int)";
my $pattern = qr(^(int));

if ( $line =~ /$pattern/ ) {
print "line matched";
} else {
print "line not matched";
}


It is not matching.



Can you please help with a pattern which matches this line



Thanks.










share|improve this question























  • Your code is working for me in this demo.

    – Tim Biegeleisen
    Nov 19 '18 at 5:27











  • Thanks Tim. Online it is working. I have use perl-5.8.3. It is not working for me. Thanks

    – sanapala mohanarao
    Nov 19 '18 at 5:34
















1















I have tried the below code



my $line = "(int)";
my $pattern = qr(^(int));

if ( $line =~ /$pattern/ ) {
print "line matched";
} else {
print "line not matched";
}


It is not matching.



Can you please help with a pattern which matches this line



Thanks.










share|improve this question























  • Your code is working for me in this demo.

    – Tim Biegeleisen
    Nov 19 '18 at 5:27











  • Thanks Tim. Online it is working. I have use perl-5.8.3. It is not working for me. Thanks

    – sanapala mohanarao
    Nov 19 '18 at 5:34














1












1








1








I have tried the below code



my $line = "(int)";
my $pattern = qr(^(int));

if ( $line =~ /$pattern/ ) {
print "line matched";
} else {
print "line not matched";
}


It is not matching.



Can you please help with a pattern which matches this line



Thanks.










share|improve this question














I have tried the below code



my $line = "(int)";
my $pattern = qr(^(int));

if ( $line =~ /$pattern/ ) {
print "line matched";
} else {
print "line not matched";
}


It is not matching.



Can you please help with a pattern which matches this line



Thanks.







regex perl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 5:24









sanapala mohanaraosanapala mohanarao

5912




5912













  • Your code is working for me in this demo.

    – Tim Biegeleisen
    Nov 19 '18 at 5:27











  • Thanks Tim. Online it is working. I have use perl-5.8.3. It is not working for me. Thanks

    – sanapala mohanarao
    Nov 19 '18 at 5:34



















  • Your code is working for me in this demo.

    – Tim Biegeleisen
    Nov 19 '18 at 5:27











  • Thanks Tim. Online it is working. I have use perl-5.8.3. It is not working for me. Thanks

    – sanapala mohanarao
    Nov 19 '18 at 5:34

















Your code is working for me in this demo.

– Tim Biegeleisen
Nov 19 '18 at 5:27





Your code is working for me in this demo.

– Tim Biegeleisen
Nov 19 '18 at 5:27













Thanks Tim. Online it is working. I have use perl-5.8.3. It is not working for me. Thanks

– sanapala mohanarao
Nov 19 '18 at 5:34





Thanks Tim. Online it is working. I have use perl-5.8.3. It is not working for me. Thanks

– sanapala mohanarao
Nov 19 '18 at 5:34












1 Answer
1






active

oldest

votes


















6














I believe earlier versions of perl may have had a bug like this, where if you use to escape a regex metacharacter that is also the quoted construct delimiter, it is treated as the metacharacter, not a literal character. Try using a different delimiter for your regex, e.g. qr/^(int)/.





$ for v in 10 12 14 16 18 20 22 24 26 ; do
echo "5.$v"
"5.${v}t"/bin/perl -le'print qr(^(int))'
echo
done
5.10
(?-xism:^(int))

5.12
(?-xism:^(int))

5.14
(?^:^(int))

5.16
(?^:^(int))

5.18
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.20
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.22
(?^:^(int))

5.24
(?^:^(int))

5.26
(?^:^(int))


So 5.18 added a warning when you use an escaped delimiter (even if warnings are off), and 5.22 changed the behavior.



(Almost like a deprecation cycle except that the warning warned that you might not have expected the old behavior, not of the coming new behavior, which seems unfortunate.)






share|improve this answer


























  • Any idea where the break-point version is?

    – Jonathan Leffler
    Nov 19 '18 at 5:39











  • @JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

    – ysth
    Nov 19 '18 at 5:41











  • @ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

    – sanapala mohanarao
    Nov 19 '18 at 5:45











  • How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

    – Jonathan Leffler
    Nov 19 '18 at 5:49











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%2f53368755%2fregex-matching-with-in-perl%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









6














I believe earlier versions of perl may have had a bug like this, where if you use to escape a regex metacharacter that is also the quoted construct delimiter, it is treated as the metacharacter, not a literal character. Try using a different delimiter for your regex, e.g. qr/^(int)/.





$ for v in 10 12 14 16 18 20 22 24 26 ; do
echo "5.$v"
"5.${v}t"/bin/perl -le'print qr(^(int))'
echo
done
5.10
(?-xism:^(int))

5.12
(?-xism:^(int))

5.14
(?^:^(int))

5.16
(?^:^(int))

5.18
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.20
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.22
(?^:^(int))

5.24
(?^:^(int))

5.26
(?^:^(int))


So 5.18 added a warning when you use an escaped delimiter (even if warnings are off), and 5.22 changed the behavior.



(Almost like a deprecation cycle except that the warning warned that you might not have expected the old behavior, not of the coming new behavior, which seems unfortunate.)






share|improve this answer


























  • Any idea where the break-point version is?

    – Jonathan Leffler
    Nov 19 '18 at 5:39











  • @JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

    – ysth
    Nov 19 '18 at 5:41











  • @ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

    – sanapala mohanarao
    Nov 19 '18 at 5:45











  • How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

    – Jonathan Leffler
    Nov 19 '18 at 5:49
















6














I believe earlier versions of perl may have had a bug like this, where if you use to escape a regex metacharacter that is also the quoted construct delimiter, it is treated as the metacharacter, not a literal character. Try using a different delimiter for your regex, e.g. qr/^(int)/.





$ for v in 10 12 14 16 18 20 22 24 26 ; do
echo "5.$v"
"5.${v}t"/bin/perl -le'print qr(^(int))'
echo
done
5.10
(?-xism:^(int))

5.12
(?-xism:^(int))

5.14
(?^:^(int))

5.16
(?^:^(int))

5.18
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.20
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.22
(?^:^(int))

5.24
(?^:^(int))

5.26
(?^:^(int))


So 5.18 added a warning when you use an escaped delimiter (even if warnings are off), and 5.22 changed the behavior.



(Almost like a deprecation cycle except that the warning warned that you might not have expected the old behavior, not of the coming new behavior, which seems unfortunate.)






share|improve this answer


























  • Any idea where the break-point version is?

    – Jonathan Leffler
    Nov 19 '18 at 5:39











  • @JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

    – ysth
    Nov 19 '18 at 5:41











  • @ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

    – sanapala mohanarao
    Nov 19 '18 at 5:45











  • How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

    – Jonathan Leffler
    Nov 19 '18 at 5:49














6












6








6







I believe earlier versions of perl may have had a bug like this, where if you use to escape a regex metacharacter that is also the quoted construct delimiter, it is treated as the metacharacter, not a literal character. Try using a different delimiter for your regex, e.g. qr/^(int)/.





$ for v in 10 12 14 16 18 20 22 24 26 ; do
echo "5.$v"
"5.${v}t"/bin/perl -le'print qr(^(int))'
echo
done
5.10
(?-xism:^(int))

5.12
(?-xism:^(int))

5.14
(?^:^(int))

5.16
(?^:^(int))

5.18
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.20
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.22
(?^:^(int))

5.24
(?^:^(int))

5.26
(?^:^(int))


So 5.18 added a warning when you use an escaped delimiter (even if warnings are off), and 5.22 changed the behavior.



(Almost like a deprecation cycle except that the warning warned that you might not have expected the old behavior, not of the coming new behavior, which seems unfortunate.)






share|improve this answer















I believe earlier versions of perl may have had a bug like this, where if you use to escape a regex metacharacter that is also the quoted construct delimiter, it is treated as the metacharacter, not a literal character. Try using a different delimiter for your regex, e.g. qr/^(int)/.





$ for v in 10 12 14 16 18 20 22 24 26 ; do
echo "5.$v"
"5.${v}t"/bin/perl -le'print qr(^(int))'
echo
done
5.10
(?-xism:^(int))

5.12
(?-xism:^(int))

5.14
(?^:^(int))

5.16
(?^:^(int))

5.18
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.20
Useless use of ''; doesn't escape metacharacter '(' at -e line 1.
(?^:^(int))

5.22
(?^:^(int))

5.24
(?^:^(int))

5.26
(?^:^(int))


So 5.18 added a warning when you use an escaped delimiter (even if warnings are off), and 5.22 changed the behavior.



(Almost like a deprecation cycle except that the warning warned that you might not have expected the old behavior, not of the coming new behavior, which seems unfortunate.)







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 2:34

























answered Nov 19 '18 at 5:36









ysthysth

78.3k494192




78.3k494192













  • Any idea where the break-point version is?

    – Jonathan Leffler
    Nov 19 '18 at 5:39











  • @JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

    – ysth
    Nov 19 '18 at 5:41











  • @ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

    – sanapala mohanarao
    Nov 19 '18 at 5:45











  • How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

    – Jonathan Leffler
    Nov 19 '18 at 5:49



















  • Any idea where the break-point version is?

    – Jonathan Leffler
    Nov 19 '18 at 5:39











  • @JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

    – ysth
    Nov 19 '18 at 5:41











  • @ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

    – sanapala mohanarao
    Nov 19 '18 at 5:45











  • How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

    – Jonathan Leffler
    Nov 19 '18 at 5:49

















Any idea where the break-point version is?

– Jonathan Leffler
Nov 19 '18 at 5:39





Any idea where the break-point version is?

– Jonathan Leffler
Nov 19 '18 at 5:39













@JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

– ysth
Nov 19 '18 at 5:41





@JonathanLeffler Nope. Apparently it fails on 5.8.3. It works for me on 5.22.

– ysth
Nov 19 '18 at 5:41













@ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

– sanapala mohanarao
Nov 19 '18 at 5:45





@ysth I tried it. qr/^(int)/ worked fine in 5.8.3. Thanks.

– sanapala mohanarao
Nov 19 '18 at 5:45













How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

– Jonathan Leffler
Nov 19 '18 at 5:49





How many years gap is that? Quite a lot! (Perl's releases are documented on CPAN. 5.8.3 was released 2004-04-21; 5.8.9 on 2008-12-14; 5.22.0 on 2015-06-01. So that spans a decade. Not complaining, just commenting.)

– Jonathan Leffler
Nov 19 '18 at 5:49




















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%2f53368755%2fregex-matching-with-in-perl%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

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word