match

Why does string.match(…)[0] throws an exception?

∥☆過路亽.° 提交于 2021-02-05 11:19:26
问题 I'm trying to pull the first occurence of a regex pattern from a string all in one statement to make my code look cleaner. This is what I want to do: var matchedString = somestring.match(/some regex/g)[0]; I would expect this to be legal but it throws an exception: Exception: somestring.match(...) is null It seems like JS is trying to index the array before match is finsihed, as the array does provide atleast one match, so I don't expect it to be null. I would like some insight in why it

grep exact match in vector inside a list in R

扶醉桌前 提交于 2021-02-05 08:14:09
问题 I have a list like this: map_tmp <- list("ABC", c("EGF", "HIJ"), c("KML", "ABC-IOP"), "SIN", "KMLLL") > grep("ABC", map_tmp) [1] 1 3 > grep("^ABC$", map_tmp) [1] 1 # by using regex, I get the index of "ABC" in the list > grep("^KML$", map_tmp) [1] 5 # I wanted 3, but I got 5. Claiming the end of a string by "$" didn't help in this case. > grep("^HIJ$", map_tmp) integer(0) # the regex do not return to me the index of a string inside the vector How can I get the index of a string (exact match)

Why C++ template type match doesn't retrieve reference qualifier '&'?

点点圈 提交于 2021-02-05 05:56:12
问题 I've got the following program: #include<stdio.h> template<class T> void f(T t) { t += 1; } template<class T> void g(T &t) { t += 10; } int main() { int n=0; int&i=n; f(i); g(i); printf("%d\n",n); return 0; } I expect that because i is a reference to n , so I expect that the template function f should get int& for template type T . But in fact it doesn't. The output of the program is 10 , not 11 as I expected. So my question is, for f , why T matches int but not int& of variable i ? What's

Match values to nearest value in another array in R [duplicate]

狂风中的少年 提交于 2021-02-04 07:31:05
问题 This question already has answers here : return index from a vector of the value closest to a given element (3 answers) Closed 3 years ago . I need to match a value to its nearest corresponding value in R and extract its index. The command FindInterval(value,array) achieves this but only works if the array is in ascending order. The command match(value,array) only works if the value provides an exact match to one in the array. For example, array <- c(0.1,0.5,0.6,0.3,0.9,1.4,0.45) value <- 0

Excel - Matching entries in a column but on 2 different sheets

大憨熊 提交于 2021-01-29 18:51:01
问题 I'm trying to compare 2 columns but on 2 different sheets. One is using a query and pulling straight from a SQL database but the other is grabbing data from a query within Access. The queries are slightly different so the results aren't identical which is why i need to compare the 2 columns. Each sheet has a column (job number) and all i want to do is create another column on each excel sheet that simply says "Yes" or "No" based on whether that job number appears on the other sheet. They won

MongoDB match array based on document value [duplicate]

半腔热情 提交于 2021-01-29 13:16:45
问题 This question already has answers here : Retrieve only the queried element in an object array in MongoDB collection (14 answers) MongoDb query condition on comparing 2 fields (4 answers) Closed 10 months ago . Let's say I have the following document structure: { "A": { "_id": "ID0" }, "B": [ "a": { "_id": "ID0", "field": "X" }, "b": { "_id": "ID1", "field": "Y" } ] } I want to project B matched with the _id in A . The end result would be: { "B": [ "a": { "_id": "ID0", "field": "X" } ] } I

How to match dates in 2 data frames in R, then sum specific range of values up to that date?

六眼飞鱼酱① 提交于 2021-01-29 04:35:33
问题 I have two data frames: rainfall data collected daily and nitrate concentrations of water samples collected irregularly, approximately once a month. I would like to create a vector of values for each nitrate concentration that is the sum of the previous 5 days' rainfall. Basically, I need to match the nitrate date with the rain date, sum the previous 5 days' rainfall, then print the sum with the nitrate data. I think I need to either make a function , a for loop, or use tapply to do this, but

How to group data using mongo-template

只愿长相守 提交于 2021-01-28 11:27:17
问题 I have to filter data based on a criteria and set a field isObtained true or false. Then I am trying to group the data based on field grade . This is my data: { "school": "xyz", "studentName": "John Doe", "grade": "first", "Hobbies": [ "Painting", "Singing" ], "language": [ "English" ], "sport": "Badminton", "totalStudyHours": 85 }, { "school": xyz, "studentName": "Jane Doe", "grade": "third", "Hobbies": [ "Painting", ], "language": [ "Spanish" ], "sport": "Karate", "totalStudyHours": 65 }, {

VLOOKUP across several columns in two workbooks

家住魔仙堡 提交于 2021-01-28 05:49:00
问题 I have 2 workbooks. First is called June2122.xls It has columns such as Last Name (B2:B300), First Name (C2:B300), etc... Second is June Emails.xls It has columns such as Last Name (B2:B300), First Name (C2:C300), Email Address (D2:D300). These three columns are in a name range called Data_Table What I need to do is compare the First Name and Last Name (B2:C2) from June2122.xls with the First Name and Last Name (B2:C2) from June Emails.xls . If they match then I need to populate the email

Check if List is part of List keeping order and find postion

放肆的年华 提交于 2021-01-28 05:11:58
问题 I need to seek the "matchingpoint" of two list where List "a" is bigger than List "b". So far I've found this earlier post: Check if a list is part of another list while preserving the list sequence That helps a lot. But I need to now, where the lists fit. a = [3, 4, 1, 2, 4, 1, 5] b = [4, 1, 2] "b" fits in "a" but instead of a TRUE value I would like to have a[1] as first matchingpoint 回答1: You could use next to fetch the first matching point : a = [3, 4, 1, 2, 4, 1, 5] b = [4, 1, 2]