regular expression

G

giampiero

there is a way using regular expression to detect if in a string there
is a substring and its rotation. es 000012340003412000?
thanx a lot
 
B

Bart Van der Donck

giampiero said:
there is a way using regular expression to detect if in a string there
is a substring and its rotation.

Does this help you ?

#!perl
use strict;
use warnings;
use String::Substrings;
my $b='AF452UFA25';
my @r=();
my $prev='none';
my @p=substrings $b;
my @out=grep($_ ne $prev && ($prev=$_),sort @p);
for (@out) {
push @r, $_
if($b=~/$_/ && $b=~/@{[my $o=reverse]}/ && length>1)
}

# small report utility
print "\nFollowing substrings appear reversed in '$b':";
print "\n".$_ for @r;

I'm leaving out substrings that only consist of 1 character (they would
always be in the result array obviously).

String::Substrings is at
http://cpan.uwinnipeg.ca/dist/String-Substrings.
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top