Questions tagged [string-search]

String searching algorithms (also known as string matching algorithms) are an important class of string algorithms that try to find a place where one or several strings (also called patterns) are found within a larger string or text.

String searching algorithms (also known as string matching algorithms) are an important class of string algorithms that try to find a place where one or several strings (also called patterns) are found within a larger string or text.

Use this tag for programming questions related to string searching algorithms.

Source: Wikipedia

261 questions
8
votes
3 answers

Regular expression to only match X number of characters from end of line

Below you'll see a small excerpt of matches from the string 'octeon' in a 32b memory dump from a proprietary routing device. As you can see it contains some adjusted ASCII extending to 16 characters from the end of the line, then four 32-bit words…
zetavolt
  • 2,989
  • 1
  • 23
  • 33
8
votes
3 answers

What are the shift rules for Boyer–Moore string search algorithm?

I have been trying to understand shift rules in Boyer–Moore string search algorithm but haven't understood them. I read here on wikipedia but that is too complex ! It will be of great help if someone lists the rule in a simple manner.
saplingPro
  • 20,769
  • 53
  • 137
  • 195
7
votes
4 answers

stripos returns false when special characters is used

I am using the stripos function to check if a string is located inside another string, ignoring any cases. Here is the problem: stripos("ø", "Ø") returns false. While stripos("Ø", "Ø") returns true. As you might see, it looks like the function…
foens
  • 8,642
  • 2
  • 36
  • 48
7
votes
8 answers

what's the fastest way to scan a very large file in java?

Imagine I have a very large text file. Performance really matters. All I want to do is to scan it to look for a certain string. Maybe I want to count how many I have of those, but it really is not the point. The point is: what's the fastest way ?…
chacko
  • 5,004
  • 9
  • 31
  • 39
7
votes
3 answers

Matching bit strings

I have needed to implement a string searching algorithm that finds a pattern of bits in a text of bits (the match may not be byte/word aligned). For starters, I implemented the Boyer-Moore algorithm, but comparing individual bits was too slow for my…
scientiaesthete
  • 919
  • 9
  • 20
6
votes
2 answers

extract strings from a binary file in python

I have a project where I am given a file and i need to extract the strings from the file. Basically think of the "strings" command in linux but i'm doing this in python. The next condition is that the file is given to me as a stream (e.g. string) so…
tjac
  • 797
  • 2
  • 9
  • 16
6
votes
2 answers

php find string

how to find if this string : 132,139,150,166,176 is in this one? : 132,139,150,166,176,131,140,151,165,175
Ste
  • 1,497
  • 8
  • 33
  • 63
6
votes
2 answers

.includes() algorithm and speed?

I'm interested to know what algorithm the .includes() method uses? Does it use a modularized hash like rabin karp? I'm somewhat hesitant to use .includes() without knowing more about its methodology and speed. The documentation I've found doesn't…
Babra Cunningham
  • 2,949
  • 1
  • 23
  • 50
6
votes
1 answer

Octave - return the position of the first occurrence of a string in a cell array

Is there a function in Octave that returns the position of the first occurrence of a string in a cell array? I found findstr but this returns a vector, which I do not want. I want what index does but it only works for strings. If there is no such…
CH123
  • 251
  • 1
  • 5
  • 15
5
votes
7 answers

Replace repeating strings in a string

I'm trying to find (and replace) repeated string in a string. My string can look like this: Lorem ipsum dolor sit amet sit amet sit amet sit nostrud exercitation amit sit ullamco laboris nisi ut aliquip ex ea commodo consequat. This should…
Nin
  • 2,960
  • 21
  • 30
5
votes
1 answer

Product name string matching against a trie (supporting omissions)

I have a list of CPU models. Right now, I think the most suitable approach would be forming a trie from the list, like this: Intel -- Core -- i -- 3 | | |- 5 | | |- 7 | | -- 9 | | | …
5
votes
2 answers

PHP Array values in string?

I have been looking around for a while in the PHP manual and can't find any command that does what I want. I have an array with Keys and Values, example: $Fields = array("Color"=>"Bl","Taste"=>"Good","Height"=>"Tall"); Then I have a string, for…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
5
votes
1 answer

searching static list of fixed strings in a huge number of files

I have a large number of fixed strings (~5 million) that i want to search in a a lot of files. I saw that two of the most commonly used algorithms for string searching using finite set of patterns are: Aho-Corasick and Commentz-Walter. My goal is to…
sborpo
  • 928
  • 7
  • 15
5
votes
5 answers

Find String Between Two Substrings in Python When There is A Space After First Substring

While there are several posts on StackOverflow that are similar to this, none of them involve a situation when the target string is one space after one of the substrings. I have the following string (example_string): [?] I want…
Foobar
  • 7,458
  • 16
  • 81
  • 161
5
votes
1 answer

Understanding the Baeza-Yates Régnier algorithm (multiple string matching, extended from Boyer-Moore)

First of all, excuse me if I write a lot, I tried to summarize my research so that everyone can understand. R. Baeza-Yates and M. Regnier published in 1990 a new algorithm for searching a two dimensional mm pattern in a two dimensional nn text. The…
Delgan
  • 18,571
  • 11
  • 90
  • 141
1
2
3
17 18