String question

G

GeekX

How to select substring?

from: "abcde *:; fghijkl mno pqrstuwxyz"

I want: everything between and icluding "cde" and "stu".
That is: "cde *:; fghijkl mno pqrstu"

Thanks!
 
A

A. Sinan Unur

How to select substring?

from: "abcde *:; fghijkl mno pqrstuwxyz"

I want: everything between and icluding "cde" and "stu".
That is: "cde *:; fghijkl mno pqrstu"

Please read the posting guidelines for this group. They contain
invaluable information on how you can help yourself, and help others
help you.

perldoc -f index
perldoc -f substr

or, you can use a capturing regex match.

#!/usr/bin/perl

use strict;
use warnings;

my $s = "abcde *:; fghijkl mno pqrstuwxyz";
my $start = index $s, 'c';
my $end = index $s, 'w';
my $r = substr$s, $start, $end - $start;

print $r."\n";

if($s =~ /(c.+u)/ ) {
print $1."\n";
}

__END__

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top