if I have string let say "abcddgert234edddscddvbasdeddd" and if I want to search a pattern "ddd" what would be the raw logic?
Some sort of String searching algorithm
if I have string let say "abcddgert234edddscddvbasdeddd" and if I want to search a pattern "ddd" what would be the raw logic?
Some sort of String searching algorithm
There is no raw logic. Although i did see the pcre inner workings presentation somewhere on the web.
The simplest thing is to go over the string, start to end. You can find such sequences easily enough.
Using a regex, you can try (.)\1{2,}
- this searches for sequences of three or more of the same character. Not all regex flavors allow this - it depends on your language.
Raw searching alogs
http://en.wikipedia.org/wiki/String%5Fsearching%5Falgorithm
simplest one
bool flag = false;
for(int i=0;i<=text.length;i++)
{
if(text[i]==stringToBeSearched[0])
{
flag=true;
for(j=1;j<=stringToBeSearched.length;j++)
{
if(text[i]==stringToBeSearched[j])
{
i++;
flag=true;
}
else
{
flag=false;
break;
}
}
}
}
It is a pseudocode and it might need some optimization.
you should clearly defined what is "ddd". Depending on what you use, it might be just passing this "ddd" string to a "parser", eg grep
grep "ddd" file
or languages with regex syntax,
perl -ne 'print if (/ddd/)' file
otherwise, if its really RAW logic you want, ie, go through the string 1 char by 1 char
for each char in string
if char is "d":
if check next char is "d":
if check next char is "d":
print "found"