Separate last name and firstname using openoffice formula - openoffice-calc

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

Related

Extract data from dataset

I need to extract title from name but cannot understand how it is working . I have provided the code below :
combine = [traindata , testdata]
for dataset in combine:
dataset["title"] = dataset["Name"].str.extract(' ([A-Za-z]+)\.' , expand = False )
There is no error but i need to understand the working of above code
Name
Braund, Mr. Owen Harris
Cumings, Mrs. John Bradley (Florence Briggs Thayer)
Heikkinen, Miss. Laina
Futrelle, Mrs. Jacques Heath (Lily May Peel)
Allen, Mr. William Henry
Moran, Mr. James
above is the name feature from csv file and in dataset["title"] it stores the title of each name that is mr , miss , master , etc
Your code extracts the title from name using pandas.Series.str.extract function which uses regex
pandas.series.str.extract - Extract capture groups in the regex pat as columns in a DataFrame.
' ([A-Za-z]+)\.' this is a regex pattern in your code which finds the part of string that is here Name wherever a . is present.
[A-Za-z] - this part of pattern looks for charaters between alphabetic range of a-z and A-Z
+ it states that there can be more than one character
\. looks for following . after a part of string
An example is provided on the link above where it extracts a part from
string and puts the parts in seprate columns
I found this specific response with the link very helpful on how to use the 'str's extract method and put the strings in columns and series with changing the expand's value from True to False.

How to extract multiple names with capital letters in Google Sheets?

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 ","
"))," "))

Convert MS Outlook formatted email addresses to names of attendees using RegEx

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.

How to get the previous and next line and discard rest of the lines including white-spaces through regex?

Below is my regex code but so far I cannot fetch the desired output.
(?:^|\r?\n)(.*?)\s\n?r([A-Z]+)r?\n\s(.*?)(?:\r?\n|$)
The input:
INT. JOHN AND LORI'S APARTMENT - NIGHT
John and Lori burst in with the remains of Ted. They're
both drenched from the rain. Lori frantically searches
drawers for sewing materials. She finds a needle and
thread, and John puts Ted on the table. Lori starts to
sew him up as John watches intently.
LORI
John... I don't know if this is gonna--
JOHN
Just try. Please. Just try.
I am aiming to get the output in the following manner:
John... I don't know if this is gonna--
JOHN
Just try. Please. Just try.
You could try using:
'[^\w] ([A-Z]+\\n\\n.+\\n)'
Explanation
'[^\w] - Make sure no letter appers before capitalized text (e.g LORI, JOHN)
[A-Z]+\\n\\n - Look for a capitalized word followed by a blank line
.+\\n - Look for any sign that appears more than once and ends with new line.
This finds the next line after capitalized name
Example
Using python regex, text holds your entire text:
import re
output = re.findall('[^\w] ([A-Z]+\\n\\n.+\\n)', text)
print output
This will output:
LORI
John... I don't know if this is gonna--
JOHN
Just try. Please. Just try.

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