Is it possible to use one regex to convert both
Doe, John C., Jr., M.D.
Doe, Jane, M.D.
to read
John C. Doe Jr., M.D.
Jane Doe, M.D.
Replace
^([^,]+),\s([^,]+),(?:(\s[^,]+),)?\s([^,]+)$
with
$2 $1$3, $4
DEMO
Barmar's answer works for the specified examples, but there's a possibly simpler solution which should satisfy our input:
Replace ^([^,]+),\s([^,]+),(.*)$ with $2 $1$3
We replace the (?:(\s[^,]+),)?\s([^,]+) with a simpler (.*) that grabs all titles after the first name (we don't care about the specifics of what's in these titles).
Related
I am looking for regex that will allow me to extract the names and drop everything inside the parentheses. Example data below.
Text string:
John (Juan, Jonathan, Jon, Jonny) James Doe (born on January 1, 1900)
Desired output:
John James Doe
Further in some cases the text string may be like:
John (Juan, Jonathan, Jon, Jonny) James Doe (born on January 1, 1900) (Canada)
and in this case we would still want returned:
John James Doe
I tried the solution from the linked question, but I still get the wrong output:
John James Doe (born on January 1, 1900)
Using regex only and not any replace function :
[^\S]*(\w*)(?:\s*)(?:\([^()]*\))*
https://regex101.com/r/zF2cMM/4
Edit :
(?:[^\S]*(\w*)(?:\s*)(?:\s*\([^()]*\)\S*)*)
I have made this last one version correcting a problem on last match
You can compare V4 and V6 and see that the result is a little bit different
https://regex101.com/r/zF2cMM/6
Now this work fine.
If you have a moment, I need some help adding to my regex expression. I am validating a response in a Google Form for the user's full name.
The validation requires:
That only letters are used
That the user inputs both the first and second name (at a minimum), separated by a space
So far I have come up with:
[a-zA-Z ]+]
But this lacks the check for a minimum of two words in a given string.
After an hour of fails and googling, I have admitted defeat and need your help!
Thanks in advance.
This should do the job:
/^[a-z]{2,}( [a-z]+)*?( [a-z]{2,}){1,}$/i
It matches:
john smith ◄ all lowercase
John Smith
John P E Smith
John Paul E Smith
John Paul Eward Smith
It ignores:
John
John S
John Paul S
John Paul Edward S
J0hn Smith ◄ zero instead of the letter 'o'
John Smith ◄ multiple spaces
You can play with this fiddle.
Best regards
So I am reading in a string and it is always split by x # y, with x or y being its own string such as "John Doe" and "Jane Doe". My regex currently gets the string "John Doe " and " Jane Doe". I want the line to be split on the white space with the # symbol. Does anyone know a regex for that?
Given this string: john doe # jane doe you can use this regex (.*)\s#\s(.*$) and you will have john doe and jane doe as your two capture groups.
the regex was this (\s\#\s). it worked
Let's say I have a string:
John Smith (auth.), Mary Smith, Richard Smith (eds.), Richie Jack (ed.), Jack Johnny (eds.)
I would like to match:
John Smith(auth.),Mary Smith,Richard Smith(eds.),Richie Jack(ed.),Jack Johnny(eds.)
I have came up with a regex but I have a problem with the | (or character) because my string contains characters that have to be escaped like ().. This is what I'm not able deal with. My regex is:
\s+\((auth\.\)|\(eds\.\))?,\s+
EDIT: I think now that the most universal solution would be to assume that in () could be anything.
Try this:
\s*\((auth|eds?)?\.\)?,?\s*
\s+ means one or more
\s* means zero or more
Based on your comment, I modified the regex:
\s*((\([^)]*\))|,)\s*
I have a query that returns first and last names which are output in a URL like so:
<a href="#fname#-#lname#>#fname# #lname#</a>
outputs:
John Doe
Problem is for names having a period at start or end of name, I need to reformat the name in the url to be as follows:
Doe, John G. --> Doe, John G.
Doe, G. John --> Doe, G. John
Flannery Jr., William J. --> Flannery Jr., William J.
Can I use rereplace function or some kind of regex to account for reformatting these 3 scenarios?
#REReplace(getAuthors.Fname, "\.^", "",ALL)#
Any help would be greatly appreciated - thank you!
Jon
Figured it out using replaceList function - Thanks for posting solutions anyway!
#getAuthors.Lname#, #getAuthors.Fname#