簡體   English   中英

preg_match_all忽略帶連字符的單詞

[英]preg_match_all ignore hyphenated words

我有一個preg_match_all表達式,用於查找+ - 和“並將單詞分解出去

/[+?-]*"[^"]*"|[+?-]*\b\w+\b/

但如果我有smith-cooper然后它返回smith -cooper,那么帶有連字符的單詞會給我帶來問題。 我需要它將smith-cooper作為一個條目返回。 此外,我需要-smith-cooper作為一個匹配-smith-cooper和-smith -cooper返回返回2場比賽-smith -cooper任何幫助將非常感謝

如果我理解你想要你的regexp做什么,你只需要用[\\w-]+替換\\w+ ,這樣你的名字就可以包含連字符。 \\w只匹配[a-zA-Z0-9_]

/[+?-]*"[^"]*"|[+?-]*\\b[\\w-]+\\b/

https://regex101.com/r/la5fJg/1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM