jQuery自动完成标记插件,无需重复检查(jQuery autocomplete tagging plug-in without duplicate check)
我正在寻找一个没有重复检查的jQuery自动完成标记插件。 所以你可以多次选择一个项目。 我喜欢Select2插件,但有人知道如何禁用Select2中的重复ID检查功能。 创建者在4.0.0版本中提到了该功能,但我无法找到如何禁用它。 这里提到了
I am looking for a jQuery autocomplete tagging plug-in without duplicate check. So you can select an item multiple times. I like Select2 plug in, but does anyone know how to disable the duplicate id check function in Select2. The creator mentioned that function in the 4.0.0 version but I could not find out how to disable that. It is mentioned here
原文:https://stackoverflow.com/questions/33606235
最满意答案
我不能在一行中作为正则表达式,但这是我尝试使用itertools和任何:
import pandas as pd from itertools import product url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']}) string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills'] """ For each of Cartesian product (the different combinations) of string_list and urls. """ for x in list(product(string_list, url['urls'])): """ If any of the words in the string (x[0]) are present in the URL (x[1]) disregarding case. """ if any (word.lower() in x[1].lower() for word in x[0].split()): """ Show the match. """ print ("Match String: %s URL: %s" % (x[0], x[1]))
输出:
Match String: Benefit Cosmetics URL: www.ulta.com/beautyservices/benefitbrowbar/ Match String: Anastasia Beverly Hills URL: www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA
更新:
您可以选择使用以下方式:
import pandas as pd import warnings pd.set_option('display.width', 100) """ Supress the warning it will give on a match. """ warnings.filterwarnings("ignore", 'This pattern has match groups') string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills'] """ Create a pandas DataFrame. """ url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']}) """ Using one string at a time. """ for string in string_list: """ Get the individual words in the string and concatenate them using a pipe to create a regex pattern. """ s = "|".join(string.split()) """ Update the DataFrame with True or False where the regex matches the URL. """ url[string] = url['urls'].str.contains('('+s+')', case = False) """ Show the result """ print (url)
哪个会输出:
urls Benefit Cosmetics Anastasia Beverly Hills 0 www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00... False True 1 www.ulta.com/beautyservices/benefitbrowbar/ True False
我想,如果你想在DataFrame中使用它,可能会更好,但我更喜欢第一种方式。
I can't do it as a regex in one line but here is my attempt using itertools and any:
import pandas as pd from itertools import product url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']}) string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills'] """ For each of Cartesian product (the different combinations) of string_list and urls. """ for x in list(product(string_list, url['urls'])): """ If any of the words in the string (x[0]) are present in the URL (x[1]) disregarding case. """ if any (word.lower() in x[1].lower() for word in x[0].split()): """ Show the match. """ print ("Match String: %s URL: %s" % (x[0], x[1]))
Outputs:
Match String: Benefit Cosmetics URL: www.ulta.com/beautyservices/benefitbrowbar/ Match String: Anastasia Beverly Hills URL: www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA
Updated:
The way you were looking at it you could alternatively use:
import pandas as pd import warnings pd.set_option('display.width', 100) """ Supress the warning it will give on a match. """ warnings.filterwarnings("ignore", 'This pattern has match groups') string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills'] """ Create a pandas DataFrame. """ url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']}) """ Using one string at a time. """ for string in string_list: """ Get the individual words in the string and concatenate them using a pipe to create a regex pattern. """ s = "|".join(string.split()) """ Update the DataFrame with True or False where the regex matches the URL. """ url[string] = url['urls'].str.contains('('+s+')', case = False) """ Show the result """ print (url)
which would output:
urls Benefit Cosmetics Anastasia Beverly Hills 0 www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00... False True 1 www.ulta.com/beautyservices/benefitbrowbar/ True False
Which I guess, if you want it in a DataFrame, may be better but I prefer the first way.
相关问答
更多-
检查一个字符串是否包含在另一个字符串中时的StackOverflow(StackOverflow when checking if one string is contained in another)[2023-04-25]
我不知道其余部分是否正确,但是这里有一个错误: i++在评估后增加i 。 你每次都用相同的值调用你的函数。 你可能是指++i 。 I don't know if the rest is correct, but here is one error: i++increments i after it was evaluated. You call your function with the same value every time. You probably mean ++i. -
有一个函数可以在字符串( find )中找到一个子字符串,还有一个函数用另一个字符串replace字符串中的一个特定范围( replace ),所以你可以组合它们来获得你想要的效果: bool replace(std::string& str, const std::string& from, const std::string& to) { size_t start_pos = str.find(from); if(start_pos == std::string::npos) ...
-
您可以使用Split将\从完整路径中的\分隔到PathArr数组元素,然后循环遍历PathArr元素并查找“ INC ” 。 下面的代码将为您提供“ INC ”字符数的灵活性。 码 Option Explicit Sub test() Const FullName = "C:\Users\myUser\Desktop\SVN-Folder\trunk\G\INC20825\Estimación Temporal_v01r00.xlsx" Dim INCSection As String ...
-
python regex:捕获包含空格的多个字符串的一部分(python regex: capture parts of multiple strings that contain spaces)[2022-11-07]
除非你解释这个问题还有更多,否则我没有看到使用正则表达式的重点。 使用基本字符串方法处理非常简单: [s.strip() for s in mys.split(',') if s.strip()] 或者如果它必须是一个元组: tuple(s.strip() for s in mys.split(',') if s.strip()) 代码也更具可读性。 请告诉我这是否适用。 编辑:好的,这个问题确实比最初看起来更多。 但是出于历史目的而留下这个。 (猜猜我不是'纪律':)) In order to sum ... -
尝试使用find()来代替 - 这会告诉你它在字符串中的位置: a = '1234;5' index = a.find('s') if index == -1: print "Not found." else: print "Found at index", index 如果你只是想知道字符串是否在那里,你可以用in : >>> print 's' in a False >>> print 's' not in a True Try using find() instead - this ...
-
包含在另一个字符串regex python中的字符串的一部分(part of a string contained in another string regex python)[2023-05-29]
我不能在一行中作为正则表达式,但这是我尝试使用itertools和任何: import pandas as pd from itertools import product url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']}) string_list = ['Benefit Cosmetic ... -
此代码有效: answers = [ ['person1', ' 2 1": ["answer 1"], "', ' 3 1": ["answer 0"], "'], ['person2', ' 2 1": ["answer 3"], "', ' 3 1": ["answer 1"], "']] result = [] for person_ans in answers: list = [] for val in person_ans: ...
-
你可以试试这个: preg_match_all('/"[^"]+"|\S+/', $s, $matches); 看它在线工作: ideone You could try this: preg_match_all('/"[^"]+"|\S+/', $s, $matches); See it working online: ideone
-
您可以使用以下正则表达式捕获您需要保留的内容,然后使用反向引用在子替换后恢复它: \b(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\.\d+\b 替换为\1 。 见演示 IDEONE代码: import re p = re.compile(r'\b(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\.\d+\b') test_str = u"1996-07-04 00:00:00.0" print re.sub(p, r"\1", test_s ...
-
以下查询将执行: >>> sentence = 'A brown cat jumps over a person' >>> MyModel.objects.extra(where={"%s like CONCAT('%%', `name` ,'%%')"}, ... params=[sentence]).values() [{'id': 1L, 'name': u'brown cat'}, {'id': 3L, 'name': u'person'}] Foll ...