string-matching

javascript regular expression to check for IP addresses

六月ゝ 毕业季﹏ 提交于 2019-12-27 12:04:50
问题 I have several ip addresses like: 115.42.150.37 115.42.150.38 115.42.150.50 What type of regular expression should I write if I want to search for the all the 3 ip addresses? Eg, if I do 115.42.150.* (I will be able to search for all 3 ip addresses) What I can do now is something like: /[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}/ but it can't seems to work well. Thanks. 回答1: The regex you've got already has several problems: Firstly, it contains dots. In regex, a dot means "match any

Python iterating through two files by line at the same time

让人想犯罪 __ 提交于 2019-12-25 05:17:08
问题 I am trying to compare columns in two files to see if the values match, and if there is a match I want to merge/concatenate the data for that row together. My issue is that when reading line by line from the two files separately, I can't get python to iterate through the files together and look for a match. Instead it will iterate properly through one file and iterate over the same line in the second file multiple times... I have had this issue in the past and still not really found a way

Suffix tree in Matlab

不想你离开。 提交于 2019-12-25 04:15:34
问题 I am finding longest substring in text T, such that it is a prefix of string S. I have made algorithm using suffix tree which provides less complex solution, but since Matlab doesn't use pointers or any other reference, I am stuck at the implementation. Could somebody please suggest some solution or some alternate way to this problem, possible in Matlab. 回答1: Here are a few suggestions for using "pointers" in Matlab: You can simply use cell array indexes as pointers, to reference cell array

Python - comparing columns in 2 files and returning merged output

核能气质少年 提交于 2019-12-25 03:12:18
问题 I have a seemingly simple problem but have been stuck on it for too long now. I would like to compare two files (format shown below) > file1 20 246057 0.28 68363 0 A 20 246058 0.28 68396 T C 20 246059 0.28 76700 A G 20 246060 0.28 76771 T C 20 246061 0.28 76915 0 A > file2 112879285 R 68303 20 200068921 M 68319 20 200257910 K 68336 20 200192457 W 68363 20 138777928 Y 68396 20 I want to compare file1 column 0 and 3 with file2 column 2 and 3 and if they match, I want to output the rest of the

Identify short sequences of matches between 2 strings

混江龙づ霸主 提交于 2019-12-25 02:46:42
问题 I have the following code: for k, (j,k) in enumerate (zip(line1_u,line2_u_rev_comp)): if j==k: Match1+=1 if j== 'N' or k == 'N': Unknown1+=1 if j != k: Different1+=1 This takes 2 lines (line1_u and line2_u_rev_comp) and compares them character by character to identify if they match, have an N which places it in the unknown category or are different. What I want is as well as tallying up each of these is to identify if 10 characters or more in a row match. How could this be done? Explanation

Sklearn cosine similarity for strings, Python

只愿长相守 提交于 2019-12-25 02:07:57
问题 I am writing an algorithm that checks how much a string is equal to another string. I am using Sklearn cosine similarity. My code is: from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity example_1 = ("I am okey", "I am okeu") example_2 = ("I am okey", "I am crazy") tfidf_vectorizer = TfidfVectorizer() tfidf_matrix = tfidf_vectorizer.fit_transform(example_1) result_cos = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix) print

Comparing data using lookup and output only longest phrase in the data using python?

我怕爱的太早我们不能终老 提交于 2019-12-24 22:32:20
问题 I have a csv which contains "KKR" map to "MBI" data. I want to perform a lookup from a user given data to extract the longest matched phrase from KKR (ignore small phrase if it contains words of long phrase) #os.chdir("kkr_lookup") data = pd.read_csv("KKR_MBI_MAP.csv") dfData = pd.DataFrame(data) dfVerbatim = pd.DataFrame() dataVerbatim = {'verbatim': ['She experienced skin allergy and hair loss after using it for 2-3 weeks']} dfVerbatim = pd.DataFrame(dataVerbatim, columns = ['verbatim'])

using python 3 stacks to ensure symbols match in correct pairs and the types of symbols match as well

徘徊边缘 提交于 2019-12-24 07:52:20
问题 def spc(sym): stk1=myStack() stkall=myStack() for i in sym: if i not in stk1: stk1.push(i) else: stkall.push(i) for j in stk1: for k in stkall: if j==k: stk1.pop(j) stkall.pop(k) else: pass if len(stk1) == len(stkall): print("all symbols match") else: print(("these symbols, %s, have no matches")%(stkall)) Above code gives me this error "TypeError: argument of type 'myStack' is not iterable" But I fixed it by the answer from @SergeBallesta. After I edited code to look as you see now. Now im

Q: Match rows and Insert return value in SQL (Complex condition)

廉价感情. 提交于 2019-12-24 07:49:48
问题 This is the Problem Table: UNIQUE ID NAME TYPE PRICE PAYMENT METHOD Reference hbg5-5rdw-6ts Bagui RECEIVED 150 MANUAL CREDIT CARD asd4e-4rs-5tg Cams RECEIVED 100 CASH 181088 fg6gh-rfd4-tgv Cams TRANSFER 100 CASH 181088 a3accf-wrf-aw Chels RECEIVED 700 MANUAL COD 1sder-5tg7-gcd Chels SUCCESS 500 CHECK asde-1d-sedc Chels SUCCESS 500 CHECK 1sder-5tgs7-gcd5 Failed ased-asd-sedf Duzy RECEIVED 250 DEBIT 181077 5rt4w-4sd-zsd Duzy TRANSFER 250 DEBIT 181077 4er-445ff-thc Jose RECEIVED 300 CASH 157075

Native Javascript querySelectorAll() with multiple/many pseudo selectors/matches

為{幸葍}努か 提交于 2019-12-24 06:42:21
问题 How can I place many pseudo selectors inside the native Javascript querySelectorAll()? Example: I want to search for an element with an id that starts with [id^=starting] and ends with [id$=ending]. (Couldn't find existing question so making my own and answering it) 回答1: With Native Javascript this would be the code: document.querySelectorAll('[id^=starting][id$=ending]'); or document.querySelectorAll('[id^='+startingString+'][id$='+endingString+']'); This will get an element which starts