0

How to extract the medium letter of a word using only regex for ex.:

"someWord" -> "e" or "W" no sense
"Hello" -> "l"
"Music" -> "s"
"four" -> "o" or "u" no sense

1 Answers1

0

Id does not make sense to use regex for this kind of task!

As I don't know what environmnet and language you use, I can give you just general scheme:

pattern = '^.{' + Int(Length(str)/2) + '}(.)'

or

pattern = '(?<=^.{' + Int(Length(str)/2) + '}).'
Community
  • 1
  • 1
Ωmega
  • 42,614
  • 34
  • 134
  • 203
  • 1
    the fact that it does not make sense, does not really make it an invalid question I think. Trying to get to the boundaries of what's possible with regex, might give a deeper understanding of regex for reasonable applications, as well. Just like [this](http://stackoverflow.com/q/12941362/1633117) or [this question](http://stackoverflow.com/q/12715679/1633117). They are certainly not sensible for productive use, but they teach you a lot about regexes. However, I think this problem is really beyond pure regex, even using `(?R)`. – Martin Ender Oct 29 '12 at 21:04