Help with reg.exp. 
Author Message
 Help with reg.exp.

Hi all,
I have a regular expression to find a special substring within a
string. The substring consists of 2 chars (capital) followed by 11
digits. The substring can be located anywhere within the string. I'm
using the following code to extract the substring:

($number) = $line =~ m{ ( [A-Z]{2}\d{9} ) }ix;

My problem is now that there can be multible instances of the
substring within the string, but my code only gets the first instance.
Does anyone know how to extend the code to grep all the instances of

containing one instance per element?

Thanks in advance,
Rune



Fri, 13 May 2005 09:21:20 GMT  
 Help with reg.exp.

Quote:

> Hi all,
> I have a regular expression to find a special substring within a
> string. The substring consists of 2 chars (capital) followed by 11
> digits. The substring can be located anywhere within the string. I'm
> using the following code to extract the substring:

> ($number) = $line =~ m{ ( [A-Z]{2}\d{9} ) }ix;

> My problem is now that there can be multible instances of the
> substring within the string, but my code only gets the first instance.
> Does anyone know how to extend the code to grep all the instances of

> containing one instance per element?

> Thanks in advance,
> Rune


The g switch requests a global match and will return you a list of all
matches within $line.   I have removed your i switch which is "ignore case",
since you say that you need two capital letters.

Graham

--
Graham Ellis, Well House Consultants
Melksham, Wiltshire, UK.
http://www.wellho.net



Fri, 13 May 2005 09:38:45 GMT  
 Help with reg.exp.

Quote:
>I have a regular expression to find a special substring within a
>string. The substring consists of 2 chars (capital) followed by 11
>digits. The substring can be located anywhere within the string. I'm
>using the following code to extract the substring:

>($number) = $line =~ m{ ( [A-Z]{2}\d{9} ) }ix;

>My problem is now that there can be multible instances of the
>substring within the string, but my code only gets the first instance.
>Does anyone know how to extend the code to grep all the instances of

>containing one instance per element?

Replace the ix with g.

Phil
--
Ignore coming events if you wish to send me e-mail



Fri, 13 May 2005 10:23:34 GMT  
 Help with reg.exp.
<<

My problem is now that there can be multible instances of the
substring within the string, but my code only gets the first instance.
Does anyone know how to extend the code to grep all the instances of

containing one instance per element?

put the g parameter to the end, and run it in a loop which builds up an array.



Fri, 13 May 2005 14:32:48 GMT  
 Help with reg.exp.
Help again,
My script just evolved. Now I need to support an extend string that
looks like this:

C[CCNNNNNNNNNNN]

C= Char
N= Number

The former solution looked like this:

How can I support the special characters in the string? I tried like
this, but it didn't return anything:

Could someone please help and explain me how to do it correctly?

Thanks,
Rune

Quote:

> <<

> My problem is now that there can be multible instances of the
> substring within the string, but my code only gets the first instance.
> Does anyone know how to extend the code to grep all the instances of

> containing one instance per element?

> put the g parameter to the end, and run it in a loop which builds up an array.



Mon, 30 May 2005 13:44:07 GMT  
 Help with reg.exp.

Quote:

> Now I need to support an extend string that
> looks like this:

> C[CCNNNNNNNNNNN]

> C= Char
> N= Number
> How can I support the special characters in the string? I tried like
> this, but it didn't return anything:


> Could someone please help and explain me how to do it correctly?

Your pattern requires the digits _following_ the ]

   m{ ( [A-Z]\[[A-Z]{2}\d{11}\] ) }gx;

[snip upside-down quoted text, please don't do that]

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Mon, 30 May 2005 15:14:31 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Please help re: reg exp from command line...

2. Help With Reg Exp.

3. Help with Reg Exp...

4. NEED HELP IN CREATING REG EXP

5. reg exp help, please

6. Reg exp help

7. Stumped by Reg Exp Problem - help??

8. reg exp help

9. help with removing leading zeros with reg-exp

10. Reg Exp request for help

11. SIMPLE REG-EXP Please Help!

12. SIMPLE REG-EXP Please Help!

 

 
Powered by phpBB® Forum Software