text is :
WYATT - Ranked # 855 with 0.006 % XAVIER - Ranked # 587 with 0.013 % YONG - Ranked # 921 with 0.006 % YOUNG - Ranked # 807 with 0.007 %
I want to get only
WYATT XAVIER YONG YOUNG
I tried :
(.*)?[ ]
But it gives me the :
WYATT - Ranked
SELECT SUBSTRING_INDEX(yourColumnName,' ',1) as anyVariableName from yourTableName; In the above query, if you use -1 in place of 1 then you will get the last word. To understand the above concept, let us create a table.
To find a word in the string, we are using indexOf() and contains() methods of String class. The indexOf() method is used to find an index of the specified substring in the present string. It returns a positive integer as an index if substring found else returns -1.
To extract words from a string vector, we can use word function of stringr package. For example, if we have a vector called x that contains 100 words then first 20 words can be extracted by using the command word(x,start=1,end=20,sep=fixed(" ")).
Regex is unnecessary for this. Just use some_string.split(' ', 1)[0]
or some_string.partition(' ')[0]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With