jquery autocomplete specific bold issue - jquery-autocomplete

I've got autocomplete source with values like 'JOHN SMITH', 'LIN SMITH', JOHN STAINIGER';
I want to enable user if he writes SMITH in the output to see also the suggestions ''JOHN SMITH', 'LIN SMITH' and when he writes SMITH J he should see only JOHN SMITH.
So I've made autocomplete to search both ways - JOHN S and SMITH J will both give me JOHN SMITH
The problem is with bold- I've made this function which makes the req. term item bold no matter where it finds the req. erm in the string.
But if I write SMITH J and that's my req. term then it will bold nothing because it cannot find this req. term in JOHN SMITH. How can i change that?
How can i change that
function monkeyPatchAutocomplete() {
$.ui.autocomplete.prototype._renderItem = function (ul, item) {
var highlighted = item.label.split(this.term).join('<strong>' + this.term + '</strong>');
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + highlighted + "</a>")
.appendTo(ul);
}
}

Related

Find the position of a related string in a list

In my worksheet, B2:F2 and B8:D8 are already filled in.
I would like to find the formulas for B9:D9. For instance, B9 is 2 because we can find Lee in Lee XXXX and Lee is at the second place of B2:F2. C9 is 4 because we can find Jim in Jim XXXX and Jim is at the second place of B2:F2.
To check the relation of Lee and Lee XXXX (Jim and Jim XXXX), we could use SEARCH, left_substring (if such a function exists).
Both single formulas or array formula will be fine. Using LAMBDA function is secondary choice, because it is still in preview.
Could anyone help?
If what is needed is always the first "word":
=MATCH(LEFT(B8,FIND(" ",B8)-1),$B$2:$F$2,0)
If you want to search on any position in the string:
=AGGREGATE(15,7,(COLUMN($B$2:$F$2)-MIN(COLUMN($B$2:$F$2))+1)/(ISNUMBER(SEARCH(" "&$B$2:$F$2&" "," "&B8&" "))),1)
With FILTER instead of AGGREGATE:
=#FILTER((COLUMN($B$2:$F$2)-MIN(COLUMN($B$2:$F$2))+1),ISNUMBER(SEARCH(" "&$B$2:$F$2&" "," "&B8&" ")),"")

Replace text in multi-line string using text in the same line

Here's a very dummy example of what I'm trying to accomplish, input is text:
{placeholder}, John Jones\n{placeholder}, Ben Franklin\n{placeholder}, George Washington
What I want to do is replace every instance of {placeholder} with the output of a function using data from the same line, e.g. the first initial and last name (would need to input first and last name to a function).
def initializer(name):
return f"{name.split(' ')[0][0]}. {name.split(' ')[1]}"
The desired result would be:
J. Jones, John Jones\nB. Franklin, Ben Franklin\nG. Washington, George Washington
A regular expression with a replacement function would work:
import re
s = "{placeholder}, John Jones\n{placeholder}, Ben Franklin\n{placeholder}, George Washington"
def repl_function(m):
return "{}. {}, {} {}".format(m.group(1)[0],m.group(2),m.group(1),m.group(2))
print(re.sub("\{placeholder},\s+(.*?)\s(.*)",repl_function,s))
prints:
J. Jones, John Jones
B. Franklin, Ben Franklin
G. Washington, George Washington
How does it work?
It captures {placeholder} and 2 words (until end of line, not matched by .* because re.DOTALL is not set and creates 2 groups (2 name parts).
On match, it calls the repl_function replacement function with the match object (second parameter of re.sub can be a string, a bytes object or a function which accepts one argument: the match object).
Just return the reformatted match object as string by shortening the first name and repeating the other information (this can be done in a lambda as well, but it's maybe more readable as a real function)
The following will work assuming you are using Python >= 3.6:
# it is the same function you showed in your question
def initializer(name):
return f"{name.split(' ')[0][0]}. {name.split(' ')[1]}"
s = '{placeholder}, John Jones\n{placeholder}, Ben Franklin\n{placeholder}, George Washington'
names = [name.rstrip() for name in s.split('{placeholder}, ') if name != '']
output = '\n'.join(f'{initializer(name)}, {name}' for name in names)
Output
'J. Jones, John Jones\nB. Franklin, Ben Franklin\nG. Washington, George Washington'

Excel - Use Named Range to Find and Copy Found Words to Adjacent Cell

I have a long list of sentences, and a long list of words that I need to identify in each sentence.
Sentences
Jack goes to the party with Jill.
Jill likes Paul, but he doesn't know she exists.
Jill went to party with Jack to make Paul jealous.
Jill fell down and broke her crown.
Jack came tumbling after Jill because he is infatuated with her.
Named Range Words
to
the
party
well
let's say there are over 100 words in the named range.
Output would be
Sentences Words
Jack goes to the party with Jill. to, the, party
Jill likes Paul, but he doesn't know she exists.
Jill went to party with Jack to make Paul jealous. to, party
Any help is GREATLY appreciated!~
Would a user defined function like this work?
Function COMBINETEXT(Sentence_Range As Range, Key_Range As Range)
Dim c As Range
Dim output As String
‘output = Sentence_Range & " "
For Each c In Key_Range.Cells
On Error GoTo errorHandler
If Application.WorksheetFunction.Search(c.Value, Sentence_Range) > 0 Then output = output & "/" & c.Value
errorHandler:
Next c
output = right(output,len(output) -1) ‘Will get rid of first /
COMBINETEXT = output
End Function

Google Sheets - Auto Find & Replace

I have a large spreadsheet that imports basketball statistics from various websites throughout the day and then index-matches them in other tables. My problem is that some websites use a name like "Lou Williams," while others use "Louis Williams." Each time I update one of the tabs with new data, I have to manually correct all the discrepancies between names. Is there a way to write a script that auto corrects the 10-12 names that I am constantly having to fix? I'd love to find some way to do this that is easier than doing a "Find & Replace" 10 different times.
I'd also love if these "spell checks" would happen only on 3 specific tabs, but would also be ok if it happened across the entire worksheet.
I've done some research for a solution but I'm so new to scripting that it's hard to for me to translate other people's code.
Here is a (current) list of the names I frequently have to correct
INCORRECT CORRECT
Louis Williams Lou Williams
Kelly Oubre Kelly Oubre Jr.
Patrick Mills Patty Mills
James Ennis James Ennis III
Alex Abrines Álex Abrines
Guillermo Hernangomez Guillermo Hernangómez
Ishmael Smith Ish Smith
Sergio Rodriguez Sergio Rodríguez
Larry Nance Larry Nance Jr
Luc Mbah a Moute Luc Richard Mbah a Moute
Juan Hernangomez Juancho Hernangómez
Glenn Robinson Glenn Robinson III
There are other ways to do this, but this uses a 'Name List' sheet with correct and incorrect names. Run 'fix' from the custom menu and column A names will change the names to the correct ones. Here is the code and a sample spreadsheet you can copy and run.
function onOpen() {
SpreadsheetApp.getActiveSpreadsheet().addMenu(
'Correct Names', [
{ name: 'Fix', functionName: 'changeNames' },
]);
}
function changeNames() {
var ss=SpreadsheetApp.getActiveSpreadsheet()
var allSheets = ss.getSheets() //get all sheets
var numSheets=allSheets.length
var s=ss.getSheetByName("Name List")//get the list on names to change.
var lr=s.getLastRow()
var rng= s.getRange(2, 1, lr, 2).getValues()
for(var k=0;k<numSheets;k++){//loop through sheets
var s1=ss.getSheets()[k]
var test =s1.getSheetName()
if (s1.getSheetName()== "RG" || s1.getSheetName()=="NF" || s1.getSheetName()=="SWISH"){ //Sheets to process. '||' is OR
var lr1=s1.getLastRow()
var rng1=s1.getRange(2, 1, lr1, 1).getValues()// Assumes names start on eow 2 Column A. Adjust as needed
for(i=0;i<rng1.length;i++){
for(j=0;j<rng.length;j++){
if(rng1[i][0]==rng[j][1]){//if incorrect names match
rng1[i][0]=rng[j][0] //replace incorrect name with correct name
}}}
s1.getRange(2,1, lr1, 1).setValues(rng1)//replace names
}}}
https://docs.google.com/spreadsheets/d/16DPTDTCqzhYTGVmUpb1wlNFI8ZK7xoJNZvobufXapvg/edit?usp=sharing
Changed to only run certain sheets.

Excel non-uniform data extraction

I've had a really hard time tracking down a solution for this--though I'm sure it's out there. Just not sure of the exact wording to get what I'm looking for.
I have a huge data set where some of the data is missing information so it is not uniform. I want to extract just the name into one column and the e-mail in to the next column.
The best way I can narrow this down is there is a space between each unique entry with the name always being in the first box.
Example:
John Doe
John Doe's Company
(555) 555-5555
John.doe#johndoe.com
John Doe
(555) 555-5555
John Doe
Jane Doe's Company
John.doe#johndoe.com
With the results wanted being (in two excel columns):
John Doe | john.doe#johndoe.com
John Doe |
John Doe | john.doe#johndoe.com
Any suggestions on the best way to do this would be appreciated it. To make it complicated if there was no e-mail I would want to ignore that set completely, but I could just manually check.
VBA coding:
1. Indicate in Row1 the initial row where the data begins.
2. Place a flag in this case the word "end" to indicate the end of the information.
3. Create a second sheet
Sub ToList()
Row1 = 1 'Row initial from data
Row2 = 1 'Row initial to put list
Do
Name = False
Do
field = Trim(Sheets(1).Cells(Row1, 1))
If field <> "" And LCase(field) <> "end" And Not Name Then
Sheets(2).Cells(Row2, 1) = field
Name = True
End If
Row1 = Row1 + 1
Loop Until (IIf(field = "" Or LCase(field) = "end", True, False))
fieldprev = Sheets(1).Cells(Row1 - 2, 1)
If InStr(fieldprev, "#") > 0 Then
Sheets(2).Cells(Row2, 2) = fieldprev
End If
Row2 = Row2 + 1
Loop Until (IIf(LCase(field) = "end", True, False))
End Sub
Extracting the e-mail address shouldn't be too difficult as you just need to is search for a string containing the # character. A series of search() and mid() functions can be used to separate out the individual words. Search for each instance of a space and use that value in a mid() function. Then search for # in the results and you should find the e-mail address. Extracting the name will be more difficult if the original data is very messy.
However I second the comment above about using an external script, especially for a large dataset. Excel isn't really designed for the sort of thing you are describing here.

Resources