Search File And Find Exact Match And Print Line?

Build lists of matched lines – several flavors: def lines_that_equal(line_to_match, fp): return [line for line in fp if line == line_to_match] def lines_that_contain(string, fp): return [line for line in fp if string in line] def lines_that_start_with(string, fp): return [line for line in fp if line.startswith(string)] def lines_that_end_with(string, fp): return [line for line in fp if … Read more

Regex to grab strings between square brackets

You are almost there, you just need a global match (note the /g flag): match(/\[(.*?)\]/g); Example: http://jsfiddle.net/kobi/Rbdj4/ If you want something that only captures the group (from MDN): var s = “pass[1][2011-08-21][total_passes]”; var matches = []; var pattern = /\[(.*?)\]/g; var match; while ((match = pattern.exec(s)) != null) { matches.push(match[1]); } Example: http://jsfiddle.net/kobi/6a7XN/ Another option … Read more

What does the “Nothing to repeat” error mean when using a regex in javascript?

You need to double the backslashes used to escape the regular expression special characters. However, as @Bohemian points out, most of those backslashes aren’t needed. Unfortunately, his answer suffers from the same problem as yours. What you actually want is: The backslash is being interpreted by the code that reads the string, rather than passed … Read more

Case insensitive search in Mongo

You can Use $options => i for case insensitive search. Giving some possible examples required for string match. Exact case insensitive string db.collection.find({name:{‘$regex’ : ‘^string$’, ‘$options’ : ‘i’}}) Contains string db.collection.find({name:{‘$regex’ : ‘string’, ‘$options’ : ‘i’}}) Start with string db.collection.find({name:{‘$regex’ : ‘^string’, ‘$options’ : ‘i’}}) End with string db.collection.find({name:{‘$regex’ : ‘string$’, ‘$options’ : ‘i’}}) Doesn’t … Read more

MATCH function in r [duplicate]

First you have typos in your example. Secondly, the assignment of ‘list1$test1value’ should have an ‘[i]’ added to it to not save over each round. There should also not be an ‘[i]’ added to list2$id since you want to search the entire vector for the lookup. for (i in 1:length(list1)) { list1$test1value[i] <- list2$test[match(list1$id[i], list2$id, … Read more