CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
Regex mutiple match


New User

Aug 30, 2017, 12:02 AM

Post #1 of 3 (8113 views)
Regex mutiple match Can't Post

Hi everybody,
thank you for your help!!
Let me go straight to the point: I need to run some regex that can match many times and extract all possible matches. Let me explain by one simple example

$dict="        ABACUS        "; 
$regex=" ([A-Z ]*?)([AOU])([A-Z ]*?) ";
for(;$dict =~ m@$regex@g;){
print "($1)($2)($3)\n";

This one will print out:

( )(A)(BACUS)

but I need to find the other possible matches too:

( AB)(A)(CUS)
( ABAC)(U)(S)

How I can make it?


Aug 30, 2017, 6:49 AM

Post #2 of 3 (8107 views)
Re: [gianni24] Regex mutiple match [In reply to] Can't Post

I am not certain what you need. My best guess is that you want to ignore leading and trailing whitespace and then find all partitionings of the remaining string which match a pattern. This is definitely not a job for a single regex!

If you can clarify your requirements, I will look into possible solutions.

Perhaps this is what you want.

use strict;
use warnings;
my $dict = " ABACUS ";

for my $i (0..length($dict)-1) {
$dict =~ /
next if !defined $3;
print "($1)($2)($3)\n";


Good Luck,

(This post was edited by BillKSmith on Aug 30, 2017, 7:31 AM)

New User

Sep 1, 2017, 2:46 AM

Post #3 of 3 (8083 views)
Re: [BillKSmith] Regex mutiple match [In reply to] Can't Post

Thank you Bill: you marked the point, that's exactly what I needed.

Actually my regexes are a bit more complicated than the one I posted, but your solution applied with some minor modifications!

Thank you very much!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives