C
C#3w ago
yourFriend

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:
string pattern = "."; // Match every character except new line
string pattern = "."; // Match every character except new line
But how to replace it initialString[len - i - 1] with initialString[i] character of the string initialString?
2 Replies
reflectronic
reflectronic3w ago
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
yourFriend
yourFriendOP3w ago
Thanks for info. :OOF: I should stop trying to kill a mosquito with a sword

Did you find this page helpful?