[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Igor

8/12/2008 10:11:00 PM

Hi all,

I need to create a regular expression to have a match if first 5 characters
of the string are the same as last 5 characters of the same string. And
thatâ??s easy:
^(?<group1>\w{5})\w*\k<group1>$

Nowâ??s the challenge (at least for me). First 5 characters are lowercase and
the last 5 characters is upper case, but match is still has to happen.
Converting the input string to upper/lower case is not an option as it'll
break other functionality.

I'm not sure if it's doable. Any help would be greatly appreciated.

Igor

3 Answers

eBob.com

8/13/2008 12:13:00 AM

0


"Igor" <Igor@discussions.microsoft.com> wrote in message
news:7921A392-B9E1-400F-88C0-1DDB344AEB65@microsoft.com...
> Hi all,
>
> I need to create a regular expression to have a match if first 5
> characters
> of the string are the same as last 5 characters of the same string. And
> that's easy:
> ^(?<group1>\w{5})\w*\k<group1>$
>
> Now's the challenge (at least for me). First 5 characters are lowercase
> and
> the last 5 characters is upper case, but match is still has to happen.
> Converting the input string to upper/lower case is not an option as it'll
> break other functionality.
>
> I'm not sure if it's doable. Any help would be greatly appreciated.
>
> Igor
>
The first thing that occurs to me is IgnoreCase (or maybe it's Ignorecase).
That may give you some matches which you do not want, e.g. where the first 5
characters are AbCdE and the last 5 are aBcDe. But you could recognize such
cases and toss them out.

Bob


Igor

8/13/2008 12:24:00 AM

0

Unfortunately, this doesn't work. Result with no extra entries should be
returned by Match method.

Thank you anyway,

ID

"eBob.com" wrote:

>
> "Igor" <Igor@discussions.microsoft.com> wrote in message
> news:7921A392-B9E1-400F-88C0-1DDB344AEB65@microsoft.com...
> > Hi all,
> >
> > I need to create a regular expression to have a match if first 5
> > characters
> > of the string are the same as last 5 characters of the same string. And
> > that's easy:
> > ^(?<group1>\w{5})\w*\k<group1>$
> >
> > Now's the challenge (at least for me). First 5 characters are lowercase
> > and
> > the last 5 characters is upper case, but match is still has to happen.
> > Converting the input string to upper/lower case is not an option as it'll
> > break other functionality.
> >
> > I'm not sure if it's doable. Any help would be greatly appreciated.
> >
> > Igor
> >
> The first thing that occurs to me is IgnoreCase (or maybe it's Ignorecase).
> That may give you some matches which you do not want, e.g. where the first 5
> characters are AbCdE and the last 5 are aBcDe. But you could recognize such
> cases and toss them out.
>
> Bob
>
>
>

Pavel Minaev

8/13/2008 6:34:00 AM

0

On Aug 13, 2:11 am, Igor <I...@discussions.microsoft.com> wrote:
> Hi all,
>
> I need to create a regular expression to have a match if first 5 characters
> of the string are the same as last 5 characters of the same string. And
> that’s easy:
>         ^(?<group1>\w{5})\w*\k<group1>$
>
> Now’s the challenge (at least for me). First 5 characters are lowercase and
> the last 5 characters is upper case, but match is still has to happen.
> Converting the input string to upper/lower case is not an option as it'll
> break other functionality.
>
> I'm not sure if it's doable. Any help would be greatly appreciated.

It doesn't seem to be doable with a single regex, but it doesn't seem
to be a good case for using one, anyway. Why not just use Substring()
and Equals() as needed?