I’m writing a program that determines if a string is a palindrome recursively. I’ve decided to try and use regex, but I’m having a bit of trouble understanding the syntax. What I need to do is compare the first and last char to see if they are identical. How can I go about doing this?
Thanks!
EDIT: I found this helpful: AirSource Ltd’s answer to Degvik’s question
Yes, you can determine using regex if the first and last characters are the same:
This uses a “back reference” to refer to “group 1”, which captures the first character.
Example:
You could then recursively remove the first and last characters and check again: