I’m looking for a regular expression pattern that can match adjacent characters in a string in php.
For example if I have the string “1234” I would like it to match and return
1
12
123
1234
Is this possible with regular expressions in php?
I’ve tried
$testString = '1234';
preg_match_all('/.+/', $testString, $matches);
But that just returns the entire string.
Using
strrevtrick it is possible >>Code:
Output:
See this demo.
However you should also go with simple solution without regex >>
Code:
Output:
Check this code here.