$str = 'This is a string with alphanumeric chars @ (test-exclude)';
要檢查字符串,我瞭解它的/^[a-zA-Z0-9]+$/
,但我需要檢查字符串的每個單詞並從選擇中排除這些單詞。檢查單詞是否包含字母數字
在上面的字符串中,我需要它來排除@
和(test-exclude)
。
編輯:當然,我可以通過每個單詞和工藝,而是在尋找一種優雅的方式引起循環,我已經這樣做了:
array_unique(
array_filter(
explode(' ',
preg_replace("/^[a-zA-Z0-9]+$/", ' ',
implode(' ',
array_map('strtolower',
array_column(iterator_to_array($Cursor), 'description')
)
)
)
)
)
);
在空格上分隔並刪除那些包含非單詞字符的值。 – revo
看來你只想在空白字符之間得到字母數字字符序列,所以,你可以使用['preg_match_all('〜(?<!\ S)[A-Z0-9] +(?!\ S)〜i' ,$ s,$ matches)'](https://regex101.com/r/rIxuVs/1)。 –