Velocity Reviews > Regular expression issue

# Regular expression issue

simon_s_li@hotmail.com
Guest
Posts: n/a

 01-19-2007
Hi,

I am trying to extract some letters from a piece of string, but I do
not know how many letters I need to extract.

All I know is that there are letters that follow the letter:

Example:

At the moment I am using the following regualr expression:

(XX|YY)(\w\w)(\d{1,15})

Two example strings are:

EXAMPLE 1 - XXAB123456789
EXAMPLE 2 - YYABC123456789

I know I can get the XX or YY

However in both example strings I need to get AB or ABC.

However my regular expression (XX|YY)(\w\w)(\d{1,15}) will only get AB
in EXAMPLE 1 which is correct
but it will only get AB in EXAMPLE 2 and not ABC.

If I use (XX|YY)(\w\w\w)(\d{1,15}) it will get AB1 in EXAMPLE 1 rather
than AB.

Can anyone help me?

Regards
Simon

Julian Turner
Guest
Posts: n/a

 01-19-2007

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi,
>
> I am trying to extract some letters from a piece of string, but I do
> not know how many letters I need to extract.
>
> All I know is that there are letters that follow the letter:
>
> Example:
>
> At the moment I am using the following regualr expression:
>
> (XX|YY)(\w\w)(\d{1,15})
>
> Two example strings are:
>
> EXAMPLE 1 - XXAB123456789
> EXAMPLE 2 - YYABC123456789
>
> I know I can get the XX or YY
>
> However in both example strings I need to get AB or ABC.
>
> However my regular expression (XX|YY)(\w\w)(\d{1,15}) will only get AB
> in EXAMPLE 1 which is correct
> but it will only get AB in EXAMPLE 2 and not ABC.
>
> If I use (XX|YY)(\w\w\w)(\d{1,15}) it will get AB1 in EXAMPLE 1 rather
> than AB.
>
> Can anyone help me?
>
> Regards
> Simon

Hi

Look at character ranges -> e.g. /[A-Z]/

Thus

(XX|YY)([A-Z]+)(\d{1,15})

or

(XX|YY)([A-Z]{1,3})(\d{1,15})

Regards

Julian Turner