To get the substring between two specific characters in Perl, you can use regular expressions or the `index` and `substr` functions.
In this example,
$url
with a value of "https://example.com/page?query=1"
.index
and substr
functions to extract the substring between '/'
and '?'
.my $url = "https://example.com/page?query=1";
$url =~ /\/(.*?)\?/;
my $substring = $1;
print "Substring between '/' and '?': $substring\n";
Substring between '/' and '?': page
In this example,
$str
with a value of "Hello,World!"
.index
and substr
functions to extract the substring between ','
and '!'
.my $str = "Hello,World!";
$str =~ /,(.*?)!/;
my $substring = $1;
print "Substring between ',' and '!': $substring\n";
Substring between ',' and '!': World
In this tutorial, we learned How to get Substring between two Specific Characters in Perl language with well detailed examples.