匹配(由(n)个字母数字组成的一部分由两个星号括起来)

I'm looking for a regex that accomplishes the following:

 **Only single**, alphanumeric p**art**s of **words** enclosed by two asterisks should be matched.****

From this string, "art" and "words" should be filtered.

So far, I've got \*{2}(\w+), but I'm stuck trying to figure out how to deal with the closing asterisks.

You could try this \*{2}([A-Za-z0-9]+)\*{2}

\*     <- An asterisk (escaped as * is already a symbol)
{2}    <- Repeated twice
(      <- Start of a capturing group
  [A-Za-z0-9]    <- An alphanum (careful with \w, it's the equivalent of [a-zA-Z0-9_] not [a-zA-Z0-9])
  +              <- Repeated at least once
)      <- End of the capturing group
\*     <- An asterisk (again)
{2}    <- Repeated twice
preg_match_all('~(?<=\*\*)[a-z\d]+(?=\*\*)~i', $string, $matches);

See it here in action: http://codepad.viper-7.com/OJHzEs


Here's a detailed explanation:

enter image description here