All Questions

321
votes
14answers
85863 views

How do I test multiple variables against a value?

I'm trying to make a function that will compare multiple variables to an integer and output a string of three letters. I was wondering if there was a way to translate this into Python. So say: x = 0 ...
294
votes
6answers
177860 views

What is the difference between Python's re.search and re.match?

What is the difference between the search() and match() functions in the Python re module? I've read the documentation (current documentation), but I never seem to remember it. I keep having to look...
383
votes
5answers
401303 views

Check whether a string matches a regex in JS

I want to use JavaScript (can be with jQuery) to do some client-side validation to check whether a string matches the regex: ^([a-z0-9]{5,})$ Ideally it would be an expression that returned true or...
189
votes
3answers
282077 views

Is there an R function for finding the index of an element in a vector?

In R, I have an element x and a vector v. I want to find the first index of an element in v that is equal to x. I know that one way to do this is: which(x == v)[[1]], but that seems excessively ineffi...
101
votes
12answers
320670 views

Java: method to get position of a match in a String?

String match = "hello"; String text = "0123456789hello0123456789"; int position = getPosition(match, text); // should be 10, is there such a method?
10
votes
4answers
12205 views

Conditional merge/replacement in R

I have two data frames: df1 x1 x2 1 a 2 b 3 c 4 d and df2 x1 x2 2 zz 3 qq I want to replace some of the values in df1$x2 with values in df2$x2 based on the conditional match betwee...
13
votes
2answers
12866 views

match() returns array with two matches when I expect one match

Consider the following example: <html> <body> <script type="text/javascript"> var str="filename.jpg"; var pattOne = new RegExp('\.[^\.]*$'); var pattTwo = new RegExp('(\.[^\.]*$)...
89
votes
1answers
19275 views

Why does pattern matching in Scala not work with variables?

Take the following function: def fMatch(s: String) = { s match { case "a" => println("It was a") case _ => println("It was something else") } } This pattern matches ni...
36
votes
4answers
64111 views

A method to count occurrences in a list

Is there a simple way to count the number of occurrences of all elements of a list into that same list in C#? Something like this: using System; using System.IO; using System.Text.RegularExpression...
56
votes
3answers
146486 views

Selecting rows where a column has a string like 'hsa..' (partial string match)

I have a 371MB text file containing micro RNA data. Essentially, I would like to only select those rows that have information about human microRNA. I have read in the file using a read.table. Usually...

Previous Next