Regex replace period with dash for URL formatting - regex

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#

Related

Regex return all text other than text in MULTIPLE sets of parentheses

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.

Regex - Creating validation to enforce that a string has 2+ words

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

Postgres Regex to Return first word before comma and first word after

I am trying to get the first and last name from a column using regex but I'm stumped.
I'm trying:
select
substring('SMIRTH JR, DAVID ALLEN', '^[^ ,]+') as namemodified
it should return
SMIRTH, DAVID
but it only returns the last name. I can't figure out how to get both.
I also need it to work for:
SMIRTHJR, DAVID ALLEN
since the data isn't very clean. Any ideas?
Use regexp_matches function instead of substring (assuming Postgresql 9.x):
select
regexp_matches(regexp_replace('SMIRTHJR, DAVID ALLEN','(JR|SR),', ','),
'([^\s,]+).*?(, [^\s,]+) [^\s,]+$') as namemodified
The above will return SMIRTH, DAVID for both input strings SMIRTHJR, DAVID ALLEN or SMIRTH JR, DAVID ALLEN

CSV - split full name into first and last name

I regularly need to process large lists of user data for our marketing emails. I get a lot of CSVs with full name and email address and need to split these full names into separate first name and last name values. for example:
John Smith,jsmith#gmail.com
Jane E Smith,jane-smith#example.com
Jeff B. SMith,jeff_b#demo.com
Joel K smith,joelK#demo.org
Mary Jane Smith,mjs#demo.co.uk
In all of these cases, I want Smith to go in the last name column and everything else into the first name column.
Basically, I'd like to look for the last space before the first comma and replace that last space with a comma. But, I'm lost on how to do this, so any suggestions would be greatly appreciated. Also, I'm using BBEdit to process the text file.
Try the following regex:
(.*?) (\b\w*\b)(,[^,]*$)
And the substitution:
$1,$2$3
DEMO
After substitution, the data will be as follows:
John,Smith,jsmith#gmail.com
Jane E,Smith,jane-smith#example.com
Jeff B.,SMith,jeff_b#demo.com
Joel K,smith,joelK#demo.org
Mary Jane,Smith,mjs#demo.co.uk

Regex to transpose somewhat tricky last name, first name , title

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).