This is my sample content.
aa jg hgh a hdgh a gd abc jd cc jdv dvn ab vd bacc
I am looking text containing three letters (only one time) abc
So output I am looking is an array with output:
[0] = a
[1] = a
[2] = a
[3] = a
[4] = abc
[5] = c
[6] = c
[7] = ab
[8] = bac
[9] = c
Code I am trying:
$string = "ajg hgha hdghagd abc jdajdv advnabvd bac vdhfdh .";
$pattern = "/abc/";
$search = preg_match_all($pattern, $string, $matches);
print_r($matches);
Is there any easy way to do this task?
Give this regex a try:
abc|bac|acb|bca|cab|cba|ab|ba|ac|ca|bc|cb|a|b|c
Example:
$string = "aajg hgha hdghagd abc jdccjdv dvnabvd bacc .";
$pattern = "/abc|bac|acb|bca|cab|cba|ab|ba|ac|ca|bc|cb|a|b|c/";
$search = preg_match_all($pattern, $string, $matches);
print_r($matches);
不知道我是否理解正确,但是请尝试以下模式:
a[bc]{0,2}|b[ac]{0,2}|c[ab]{0,2}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.