簡體   English   中英

如何檢測結尾有空格的單詞(Regex - C#)

[英]How to detect words with space at the end (Regex - C#)

我創建了這個正則表達式模式(?=[Ss]table[:])(.*) ,它“檢測”這些詞:

Stable       <--- Here is one space at the end
stable       <--- Here is one space at the end
Stable:
stable:

Patter 沒有檢測到這些末尾沒有空格的單詞:

Stable
stable

我應該改變什么來檢測和這兩個字!

你可以使用這個:

 (?=[Ss]table([ :]|$))(.*)

我改變的是:

([ :]|$)

假設您使用“多行”選項,這將向前看一個空格、一個冒號或行尾

當您將其添加到字符串中時,例如名稱為 str:

string str= "Stable";
            if (str[str.Length - 1] == ' ')
            {
                your block of code;
            }

暫無
暫無

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

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