Regex Question

  • Thread starter Thread starter Igor
  • Start date Start date
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
 
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
 
Unfortunately, this doesn't work. Result with no extra entries should be
returned by Match method.

Thank you anyway,

ID
 
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?
 
Back
Top