Questions tagged [matching]

For questions related to pattern matching, using character sequences or tree structures. In contrast to pattern recognition, the match described here usually has to be exact.

2735 questions
4170
votes
38 answers

How can I pair socks from a pile efficiently?

Yesterday I was pairing the socks from the clean laundry and figured out the way I was doing it is not very efficient. I was doing a naive search — picking one sock and "iterating" the pile in order to find its pair. This requires iterating over n/2…
amit
  • 175,853
  • 27
  • 231
  • 333
60
votes
9 answers

How do I do a fuzzy match of company names in MYSQL with PHP for auto-complete?

My users will import through cut and paste a large string that will contain company names. I have an existing and growing MYSQL database of companies names, each with a unique company_id. I want to be able to parse through the string and assign to…
AFG
  • 1,675
  • 3
  • 22
  • 23
58
votes
4 answers

select columns based on multiple strings with dplyr contains()

I want to select multiple columns based on their names with a regex expression. I am trying to do it with the piping syntax of the dplyr package. I checked the other topics, but only found answers about a single string. With base R: library(dplyr) …
agenis
  • 8,069
  • 5
  • 53
  • 102
57
votes
10 answers

Matching numbers with regular expressions — only digits and commas

I can't figure out how to construct a regex for the example values: 123,456,789 -12,34 1234 -8 Could you help me?
user278618
  • 19,306
  • 42
  • 126
  • 196
52
votes
5 answers

Can a range be matched in Scala?

Is it possible to match a range of values in Scala? For example: val t = 5 val m = t match { 0 until 10 => true _ => false } m would be true if t was between 0 and 10, but false otherwise. This little bit doesn't work of course, but is…
Justin Poliey
  • 16,289
  • 7
  • 37
  • 48
49
votes
10 answers

Figure out if a business name is very similar to another one - Python

I'm working with a large database of businesses. I'd like to be able to compare two business names for similarity to see if they possibly might be duplicates. Below is a list of business names that should test as having a high probability of being…
Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
46
votes
9 answers

Regular expression matching fully qualified class names

What is the best way to match fully qualified Java class name in a text? Examples: java.lang.Reflect, java.util.ArrayList, org.hibernate.Hibernate.
Chun ping Wang
  • 3,879
  • 12
  • 42
  • 53
45
votes
8 answers

Can I use regular expressions with String.Replace in C#?

For example I have code below string txt="I have strings like West, and West; and west, and Western." I would like to replace the word west or West with some other word. But I would like not to replace West in Western. Can I use regular…
Tasawer Khan
  • 5,994
  • 7
  • 46
  • 69
45
votes
8 answers

Check if value exists in column in VBA

I have a column of numbers of over 500 rows. I need to use VBA to check if variable X matches any of the values in the column. Can someone please help me?
Trung Tran
  • 13,141
  • 42
  • 113
  • 200
42
votes
3 answers

Compare Python Pandas DataFrames for matching rows

I have this DataFrame (df1) in Pandas: df1 = pd.DataFrame(np.random.rand(10,4),columns=list('ABCD')) print df1 A B C D 0.860379 0.726956 0.394529 0.833217 0.014180 0.813828 0.559891 0.339647 0.782838 0.698993 …
edesz
  • 11,756
  • 22
  • 75
  • 123
41
votes
4 answers

Recursive listing of all files matching a certain filetype in Groovy

I am trying to recursively list all files that match a particular file type in Groovy. This example almost does it. However, it does not list the files in the root folder. Is there a way to modify this to list files in the root folder? Or, is there…
shikarishambu
  • 2,219
  • 6
  • 35
  • 57
40
votes
1 answer

When to use Rabin-Karp or KMP algorithms?

I have generated an string using the following alphabet. {A,C,G,T}. And my string contains more than 10000 characters. I'm searching the following patterns in it. ATGGA TGGAC CCGT I have asked to use a string matching algorithm which has O(m+n)…
Sukeshini
  • 1,241
  • 2
  • 23
  • 48
33
votes
9 answers

Finding words after keyword in python

I want to find words that appear after a keyword (specified and searched by me) and print out the result. I know that i am suppose to use regex to do it, and i tried it out too, like this: import re s = "hi my name is ryan, and i am new to python…
Ryan
  • 359
  • 2
  • 4
  • 4
33
votes
8 answers

Hungarian Algorithm: finding minimum number of lines to cover zeroes?

I am trying to implement the Hungarian Algorithm but I am stuck on the step 5. Basically, given a n X n matrix of numbers, how can I find minimum number of vertical+horizontal lines such that the zeroes in the matrix are covered? Before someone…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
32
votes
4 answers

Pattern matching functions in Clojure?

I have used erlang in the past and it has some really useful things like pattern matching functions or "function guards". Example from erlang docs is: fact(N) when N>0 -> N * fact(N-1); fact(0) -> 1. But this could be expanded…
mikkom
  • 3,521
  • 5
  • 25
  • 39
1
2 3
99 100