Regex Question

I

Igor

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
 
E

eBob.com

Igor said:
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
 
I

Igor

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

Thank you anyway,

ID
 
P

Pavel Minaev

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 lowercaseand
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top