@Hellena-Crainicu said in Regex: How to turn more words in the line as if they were seen in the mirror?:
I thought of a much simpler solution, maybe you can help me a little bit.
Your idea is actually just a rehash of the ones provided by @guy038 and myself. You have a lot to learn yet about regex, but don’t worry, this is a good way to learn. By trying something, realising it didn’t work, you at least have opportunity to dissect it and understand yet more about regex.
I use the website rexegg.com as a good source of information. Just be aware that it refers to the many different flavours of regular expressions, not all examples will work in Notepad++. There are also other good sources of regex information available through the FAQ section of the forum.
In your regex the [A-Za-z0-9\-\'] is almost identical to the \w that we used. You also ask where the other letters went to, in finding only the last letter was returned by using \1 when your find expression had the + at the end. The reason is that at the point the capture group saved any characters the + was outside of the (). So the expression captured a single character, then as the + was processed, it AGAIN captured a character, but in doing so the capture group \1 was overwritten with the latest character. Had you put the + inside of the () you will get all characters returned, but they will be in the original order.
At the moment I think @guy038 and my solutions are as good as it gets within a regex world. Whilst we have shown it is possible with a regular expression to “mirror” (reverse) a word it does take quite a bit of coding to do so. Python (and other) language solutions work far more efficiently as they will often have higher level functions to take care of most of the hard work. In regex everything must be completed simply.
Terry