views:

53

answers:

1

OK, so I have a new project with me, it is basically on solving logical and reasoning type of problems. Like in maths you are given a figure and asked how many triangles are in it. What I have to do is.

User enters a code and a word. example

word -> example code -> aesxxasskmpaalee

here if we remove certain characters, we can form example word 4 times.

My guess was this can be achieved using preg_match_all but that would make me start from the place where i left, returning 1 as the answer, and rechecking will yield the same old result...

Am I missing something?

A: 

Don't use regular expressions. You want simple string manipulation. You can access characters in a string just like an array in PHP:

$example = 'example';
$examples[0] === 'e';

You need to iterate through your input string one character at a time and skip not matching characters.

soulmerge
sorry I am kinda sleepy right now, that's exactly what I have been doing, but what about after that? You see I have to find out how many times it occurs..how to make it ignore the last find?