Regex matching with “(” in perl
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
add a comment |
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
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
add a comment |
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
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
regex perl
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.)
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
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%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
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.)
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
add a comment |
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.)
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
add a comment |
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.)
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.)
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
add a comment |
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
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%2f53368755%2fregex-matching-with-in-perl%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
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