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
Related
I have different section (Sales, Revenue, etc) in my text. Each section will have the same people names.
Sales
Peter $235
John $300
Revenue
Peter $450
John $400
For say, Sales section, I want to grab until the end of the line with the last person name.
Sales
Peter $235
John $300
I tried this
(System.Text.RegularExpressions.Regex.Match(Text,"Sales.*((\n).+)*\n.*?John.*").Value)
but it will grab until the last occurrence of John
Thank you
You could match Sales followed by all the following lines that do not start with John.
^Sales(?:\r?\n(?!John).*)*\r?\nJohn.*
Regex demo
If you don't want to match empty lines as well:
^Sales(?:\r?\n(?!John|$).*)*\r?\nJohn.*
Regex demo
I am trying to extract contact names of a data set, however, the names are compiled in one cell and not split up by first name, middle name, last name, email, etc.
I only need to get their names because I already have a data set only with their emails, NOT their names.
How do I extract multiple case-sensitive words and split into cells?
Here's how it looks like in one cell:
I've tried several codes I've found online and this is the only thing that comes close, however, it still extracts unnecessary lower case letters which I don't need. Please help, I'm no expert with these kinds of things.
=TRANSPOSE(SPLIT(TRIM(SUBSTITUTE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(
A2,"\b\w[^A-z]*\b"," "),"\W+"," "),"[0-9]+","")," m "," "))," "))
I expect them to have the first, middle, last names to be split into new columns like this:
Tom Billy Claudia Downey Karen Dicky Steve Harvey
OR
Tom Billy Claudia Downey Karen Dicky Steve Harvey
=ARRAYFORMULA(TRIM(IFERROR(REGEXREPLACE(IFERROR(REGEXEXTRACT(IFERROR(SPLIT(A2:A,
CHAR(10))), "(.*) .*#")), "Mr. |Mrs. ", ""))))
This formula might help. i have added the conditions to replace the email id and Mr./Ms. conditions.
=TRANSPOSE(SPLIT(TRIM(SUBSTITUTE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(
REGEXREPLACE(REGEXREPLACE(A2,"([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]
{2,5})",""),"\w+[\\.]+(?)",""),"\b\w[^A-z]*\b"," "),"\W+"," "),"[0-9]+","")," m ","
"))," "))
I'm trying to use Notepadd ++ to find and replace regex to extract names from MS Outlook formatted meeting attendee details.
I copy and pasted the attendee details and got names like.
Fred Jones <Fred.Jones#example.org.au>; Bob Smith <Bob.Smith#example.org.au>; Jill Hartmann <Jill.Hartmann#example.org.au>;
I'm trying to wind up with
Fred Jones; Bob Smith; Jill Hartmann;
I've tried a number of permutations of
\B<.*>; \B
on Regex 101.
Regex is greedy, <.*> matches from the first < to the last > in one fell swoop. You want to say "any character which is neither of these" instead of just "any character".
*<[^<>]*>
The single space and asterisk before the main expression consumes any spaces before the match. Replace these matches with nothing and you will be left with just the names, like in your example.
This is a very common FAQ.
I have a record like
Mr. James M. Heilbronner
Bryan Southwick
Ismael G. Pugeda PE
I want to insert the lastname as the last word in this example it should be
Helbronner
Southwick
PE (I can just manually edit this)
and the rest should go into the first name
Mr. James M.
Bryan
Ismael G. Pugeda
=RIGHT(A2;LEN(A2)-FIND(" ";SUBSTITUTE(A2;" ";" ";LEN(A2)-LEN(SUBSTITUTE(A2;" ";""))))) this is my code for the last name but it gets all the words after the first word
edit:
I have the solution for the last name it's this code
=IF(ISERROR(FIND(" ";A2));A2;TRIM(RIGHT(A2;LEN(A2)-FIND("";SUBSTITUTE(A2;" ";"";LEN(A2)-LEN(SUBSTITUTE(A2;" ";"")))))))
the only problem is the firstname
Assuming Mr. Heilbronner resides in A2:
B2: =LEFT(A2;LEN(A2)-LEN(C2))
C2: =TRIM(RIGHT(SUBSTITUTE(A2;" ";REPT(" ";99));99))
both copied down to suit.
The basic concept I think courtesy of Jerry Beaucaire: replace all spaces with lots of spaces and then chop off a hunk from the end and remove all spaces from it. Once you have the length of the 'surname' then use that to limit the number of characters chosen for the 'first name'.
I need a regular expression, which can find names in some text content. It should match from 1 to 3 names, First-name, (Middle-name), (Surname).
I have a list of valid first-names which will be used to search the text. If the first-name is found in the text, the regular expression should get the next middle-name or/and surname, if they exists.
As an example the names below, should be valid names found:
John
John Doe
John Average Joe
Special cases:
John average Doe (if, possible it should match/find John Doe)
So far my solution is:
\b(John|Mary|Tom)\b(?:(?:([^A-Za-z]*[A-Z][^\s,]*)*[^A-Za-z]+)){0,3}
This kinda works, the problem is the limitation to only match maximum 3 words, which this doesn't.
Online test: http://regex101.com/r/aM7bS3/2
I've modified your regex HERE
You can use the following:
\b(Mogens|Victor|John)(\b\s*([A-Z]\w+)){0,2}