Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式字符串未以结尾_Regex_Expression_Match - Fatal编程技术网

Regex 正则表达式字符串未以结尾

Regex 正则表达式字符串未以结尾,regex,expression,match,Regex,Expression,Match,我有一个问题,因为有一些字符串和我的表达式不工作 例如 字符串: 1. username 2. username- 3. username-user2 表达方式: \w*username\b 现在我的表情是我俩都没事。但我只想要一个没有这个“-”字的。用户名应该是字符串中没有任何内容的最后一个单词 但是当我搜索“username-user2”时,表达式应该接受字符串。但当我只搜索“用户名”时就不是了 有人能帮我吗?我很绝望 非常感谢……如果您不介意用户名后面出现什么文本,这应该可以使用:

我有一个问题,因为有一些字符串和我的表达式不工作

例如

字符串:

1. username
2. username- 
3. username-user2
表达方式:

\w*username\b
现在我的表情是我俩都没事。但我只想要一个没有这个“-”字的。用户名应该是字符串中没有任何内容的最后一个单词

但是当我搜索“username-user2”时,表达式应该接受字符串。但当我只搜索“用户名”时就不是了

有人能帮我吗?我很绝望


非常感谢……

如果您不介意用户名后面出现什么文本,这应该可以使用:

username(?:-\w+)?$
如果这不是字符串的结尾,则可以使用以下命令:

username(?:-\w+)?[^\w]

正确的表达式是:
\w*用户名$

Eh
\w*用户名$
-用户名+字符串结尾?用户名后面可以是什么?用户名是字符串的结尾。意思是当我选中“username”时,表达式不应与“username-”或“username-user2”匹配。谢谢您的表达式\w*username$工作正常。你救了我一天。请注意,
\w*
在这里是无用的