简体   繁体   中英

regex repeated asterisk pattern matching

If I do the regex matching

preg_match('/^[*]{2}((?:[^*]|[*][^*]*[*])+?)[*]{2}(?![*]{2})/s', "**A** **B**", $matches);

I get the result for $matches I want of

Array ( [0] => **A** [1] => A )

but I am not sure how to modify the regex to yield the same result in $matches from the input text without the space in the middle, that is, "**A****B**" .

It looks like the regex matching

preg_match('/^[*]{2}((?:[^*]|[*][^*]*[*])+?)[*]{2}/s', "**A****B**", $matches);

yields the result for $matches I want of

Array ( [0] => **A** [1] => A )

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM