Re: Is it possible with RegEx

2005-11-10 Thread Shawn Corey

Gilles wrote:

Hi,

I try do to a  simple  thing :

Knowing If a string like 13 exist in a string like 123

Or if 37 exist in 12356789

I tried many solutions, but never found one good so I try to do it with
loops which more difficult but not impossible

I'd like to know if with RegExp  it's more simply


No, it's not possible with RegExp. What you want is called the Longest 
Common Subsequence. See http://www.ics.uci.edu/~eppstein/161/960229.html 
for a description of the algorithm. There are a number of modules in 
CPAN http://search.cpan.org/ under LCS 
http://search.cpan.org/search?query=lcsmode=module but since I don't 
use any, I won't recommend any.



--

Just my 0.0002 million dollars worth,
   --- Shawn

Probability is now one. Any problems that are left are your own.
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Is it possible with RegEx

2005-11-10 Thread Bob Showalter

Gilles wrote:

Hi,

I try do to a  simple  thing :

Knowing If a string like 13 exist in a string like 123

Or if 37 exist in 12356789

I tried many solutions, but never found one good so I try to do it with
loops which more difficult but not impossible

I'd like to know if with RegExp  it's more simply


If you just want to see if the string 13 is found within the string 
123, you can use the index() function:


   $found = index('123', '13') = 0;
   == false

or a simple regex:

   $found = '123' =~ /13/;
   == false

If you want to know whether '123' contains both a '1' and a '3', you can 
do something like this:


   $found = !grep $_  0, map index('123', $_), split '', '13';
   == true


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Is it possible with RegEx

2005-11-09 Thread Jeff 'japhy' Pinyan

On Nov 10, Gilles said:


I try do to a  simple  thing :

Knowing If a string like 13 exist in a string like 123

Or if 37 exist in 12356789


You're not looking for '13', you're looking for '1..3'.  The simplest 
way to do this is:


  if (123 =~ /1.*3/) {
print found 1...3\n;
  }

--
Jeff japhy Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Is it possible with RegEx

2005-11-09 Thread Timothy Johnson

Here's one thought.  I know you had in mind one regex, but it works
pretty well like this:

#

my @testNumbers = qw(1453225556
 994320100
 99887443
 1123234499
 99298281);

foreach(@testNumbers){
   if($_ =~ /1/ and $_ =~ /3/){
  print $_ has a 1 and a 3\n;
   }
}

#
-Original Message-
From: Gilles [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 09, 2005 5:50 PM
To: 'beginners perl'
Subject: RE: Is it possible with RegEx

No,
I would know if 13 (means the 2 characters) are in 123 or 145637
I'm sorry if I did not the problem clear
Gilles




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response