Is it possible to reverse a string letter by letter using only regular expression?
I am learning string manipulation. Learned a bit about
string
and StringBuilder
. Now onto Regex
and I'm trying to do everything which I do with string methods and StringBuilder methods by using Regex alone for learning purposes.
But reversing a string letter by letter seems pretty hard by just Regex.Replace(intialString, pattern, replacement)
I guess pattern can be:
But how to replace it initialString[len - i - 1]
with initialString[i]
character of the string initialString
?2 Replies
it is not possible
well. actually. i am not sure if it is not possible. it would be a very complicated pattern if it is possible. the replacement pattern can only use information contained within the match to generate the replacement string. so, you would need a regex which creates matches that contain each character and its opposite. i don't think it's possible
Thanks for info.
:OOF: I should stop trying to kill a mosquito with a sword