Questions tagged [match]

A programming concept about finding results based on some kind of search. Typically used when talking about regular expressions.

A programming concept about finding results based on some kind of search. Typically used when talking about regular expressions.

See also , ,

8645 questions
55
votes
15 answers

In Perl, is there a built in way to compare two arrays for equality?

I have two arrays of strings that I would like to compare for equality: my @array1 = ("part1", "part2", "part3", "part4"); my @array2 = ("part1", "PART2", "part3", "part4"); Is there a built-in way to compare arrays like there is for scalars? I…
Bill
  • 14,257
  • 4
  • 43
  • 55
53
votes
5 answers

regular expression to match exactly 5 digits

testing= testing.match(/(\d{5})/g); I'm reading a full html into variable. From the variable, want to grab out all numbers with the pattern of exactly 5 digits. No need to care of whether before/after this digit having other type of words. Just…
i need help
  • 2,386
  • 10
  • 54
  • 72
52
votes
9 answers

Regex Group in Perl: how to capture elements into array from regex group that matches unknown number of/multiple/variable occurrences from a string?

In Perl, how can I use one regex grouping to capture more than one occurrence that matches it, into several array elements? For example, for a string: var1=100 var2=90 var5=hello var3="a, b, c" var7=test var3=hello to process this with…
therobyouknow
  • 6,604
  • 13
  • 56
  • 73
51
votes
2 answers

Why can I compare a String to a &str using if, but not when using match?

I'm trying to implement a function that reads command line arguments and compares them to hard-coded string literals. When I do the comparison with an if statement it works like a charm: fn main() { let s = String::from("holla!"); if s ==…
robfuscator
  • 631
  • 1
  • 5
  • 13
51
votes
7 answers

Display only the n'th match of grep

onefish onechicken twofish twochicken twocows threechicken What if I want to grep for lines containing "two", but I only want the 2nd match. So I want the result "twochicken".
Andrew Tsay
  • 1,893
  • 6
  • 23
  • 35
46
votes
3 answers

Using match to find substrings in strings with only bash

Although I am almost sure this has been covered, I can't seem to find anything specific to this. As I continue my journey on learning bash I keep finding parts where I am baffled as to why things happen the way they do. Searching and replacing or…
Adesso
  • 928
  • 2
  • 13
  • 27
46
votes
4 answers

Can I use '<' and '>' in match?

I am trying to do a simple quadratic function that would return number of roots and their values via an enum: enum QuadraticResult { None, OneRoot(f32), TwoRoots(f32, f32), } fn solveQuadratic(a: f32, b: f32, c: f32) -> QuadraticResult…
dawid
  • 665
  • 2
  • 6
  • 12
43
votes
6 answers

Search and replace specific query string parameter value in javascript

I have a string which is something like this : a_href= "www.google.com/test_ref=abc"; I need to search for test_ref=abc in thisabove strinng and replace it with new value var updated_test_ref = "xyz"; a_href…
TopCoder
  • 4,206
  • 19
  • 52
  • 64
41
votes
3 answers

how to check if string contains '+' character

I want to check if my string contains a + character.I tried following code s= "ddjdjdj+kfkfkf"; if(s.contains ("\\+"){ String parts[] = s.split("\\+); s= parts[0]; // i want to strip part after + } but it doesnot give expected result.Any…
user93796
  • 18,749
  • 31
  • 94
  • 150
40
votes
7 answers

Javascript Regexp loop all matches

I'm trying to do something similar with stack overflow's rich text editor. Given this text: [Text Example][1] [1][http://www.example.com] I want to loop each [string][int] that is found which I do this way: var Text = "[Text…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
39
votes
7 answers

Lua need to split at comma

I've googled and I'm just not getting it. Seems like such a simple function, but of course Lua doesn't have it. In Python I would do string = "cat,dog" one, two = string.split(",") and then I would have two variables, one = cat. two = dog How do I…
Jaron Bradley
  • 1,079
  • 3
  • 16
  • 24
38
votes
3 answers

str_ireplace() with keeping of case

How can I use str_ireplace (or something similar) to replace some text for formatting and then return it with the same caps? Example: $original="The quick red fox jumps over the lazy brown dog."; $find="thE"; print…
Francisc
  • 77,430
  • 63
  • 180
  • 276
37
votes
3 answers

PHP compare two arrays and get the matched values not the difference

I'm trying to compare two arrays and get only the values that exist on both arrays but, unfortunately, I can't find the right array function to use... I found the array_diff() function: http://php.net/manual/en/function.array-diff.php But it's for…
Julian Paolo Dayag
  • 3,562
  • 3
  • 20
  • 32
37
votes
6 answers

ElasticSearch: How to search for a value in any field, across all types, in one or more indices?

I have two indices my_index_1 and my_index_2. Within these indices, I have the following document types: my_index_1: people organizations roles skills my_index_2: products services patents trademarks servicemarks Each of the types has different…
Information Technology
  • 2,243
  • 3
  • 30
  • 46
37
votes
4 answers

Python- how do I use re to match a whole string

I am validating the text input by a user so that it will only accept letters but not numbers. so far my code works fine when I type in a number (e.g. 56), it warns me that I should only type letters and when I type in letters it doesn't return…
Thomas
  • 1,199
  • 3
  • 13
  • 25