Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
目前我有这个: @"(\S)+",但它只是防止任何完整字符后的空格,那么我怎样才能防止第一个字符中的空格呢?
@"(\S)+"
如果要确保字符串中没有空格,请使用以下命令:
^\S+$
^将匹配锚定到字符串的开头。
^
\S+匹配一个或多个非空白字符。
\S+
$将匹配锚定到字符串的末尾。
$
如果你真的在 Apple 的 Objective-C 开发者框架中使用 NSRegularExpression 类,它应该是这样的:
@"^\\S+$"
但是,如果(我怀疑)您使用的是 C# Regex,它应该如下所示:
@"^\S+$"
(“regex”是正则表达式的通用标签。我将删除其他标签。)