[英]How to detect words with space at the end (Regex - C#)
I have created this Regex Pattern (?=[Ss]table[:])(.*)
, which "detect" these words:我创建了这个正则表达式模式(?=[Ss]table[:])(.*)
,它“检测”这些词:
Stable <--- Here is one space at the end
stable <--- Here is one space at the end
Stable:
stable:
The Patter does not detect these words which are without space at the end: Patter 没有检测到这些末尾没有空格的单词:
Stable
stable
What should I change to detect and these two Words!我应该改变什么来检测和这两个字!
You can use this:你可以使用这个:
(?=[Ss]table([ :]|$))(.*)
Al I have changed is:我改变的是:
([ :]|$)
That will look ahead for a space, a colon OR end of line - assuming you use 'multiline' option.假设您使用“多行”选项,这将向前看一个空格、一个冒号或行尾。
When you add this in string, for examle with name str:当您将其添加到字符串中时,例如名称为 str:
string str= "Stable";
if (str[str.Length - 1] == ' ')
{
your block of code;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.