I have a name “John B. Smith”, I need to change the format of the name to “Smith, John B.” I was thinking about using a regex, but I don’t fully understand it even after reading about it. Can someone help?
Also can you take a moment to explain what is going on in the expression?
Here is an example I’ve put up at Rubular.
The regex I used is
(\w+)\s+(\w+)\s+(\w+). Here is a break down of it:\w+, I am saying that I’m looking for a regex with one or more letters, numbers or underscores. This is commonly used to look for words.\s+, I’m looking for one or more space characters.()means that I want to capture (aka remember) the portion of the input that this regex matched.