簡體   English   中英

正則表達式匹配並替換縮寫

[英]Regex match and replace for abbreviations

我在以下嘗試與您匹配並替換u的出現:

"my friend u.c.l.a i c u. c that thing? u c that thing?"
"u.s should see u."

我要強制執行的規則是不應替換縮寫,因此ucla仍然是ucla,但其他所有u字母都應該替換為您。

我正在嘗試使用ruby,但這不是我想要的。

"my friend u.c.l.a i c u. c that thing? u c that thing?".gsub! /\bu(?!\.)\b/i, "you"
"u.s should see u.".gsub! /\bu(?!\.)\b/i, "you"

您的正則表達式模式應如下所示

    "my friend u.c.l.a i c u. c that thing? u c that thing?".gsub! /\bu(?!\.(?!\s))\b/i, "you";

我認為您需要以下條件:

 "my friend u.c.l.a i c u. c that thing? u c that thing?".gsub!(/\bu(?!\.(?!\s))\b/i, 'you')

暫無
暫無

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

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