[英]match any a-z/A-Z and - character after certain regular expression
i need a certain string to be in this format: [0000] anyword 我需要某个字符串以这种格式显示:[0000] anyword
so between the [] brackets i need 4 numbers, followed by a whitespace. 所以在[]括号之间,我需要4个数字,后跟一个空格。 after that only characters ranging from a to z and - characters are allowed.
之后,仅允许使用从a到z和-字符的字符。
so this should be allowed: 因此应允许:
[0000] foo-bar [0000] foo-bar
[0000] foo [0000]富
[0000] foo-bar-foo [0000] foo-bar-foo
etc.. 等等..
so far i have this: 到目前为止,我有这个:
\[[0-9]{4}\]\s
this matches the [0000] , so it maches the brackets with 4 numbers in it and the whitespace. 这与[0000]匹配,因此会匹配带有4个数字的括号和空格。 i can't seem to find something that allows charachters after that.
在那之后,我似乎找不到任何可以让性格开朗的人。 i've tried putting a single "."
我试过放一个“。” at the end of the expression as this should match any character but this doesnt seem to be working.
在表达式的末尾,因为它应该匹配任何字符,但这似乎不起作用。
\[[0-9]{4}\]\s^[A-Z]+[a-zA-Z]*$
the above isn't working either.. 以上也不起作用..
i need this expression as a Validationexpression for an asp.net custom validator. 我需要此表达式作为asp.net自定义验证程序的Validationexpression。
any help will be appreciated 任何帮助将不胜感激
(\\[[0-9]{4}\\])\\s+([Az\\-]+)
should hopefully work. (\\[[0-9]{4}\\])\\s+([Az\\-]+)
应该可以正常工作。 It'll capture the numbers and letters into two capture groups as well. 还将数字和字母捕获到两个捕获组中。
试试这个
@"\[[0-9]{4}\] [a-zA-Z]+(-[a-zA-Z]+)*"
This works for your input: http://regexr.com/?30sb7 . 这适用于您的输入: http : //regexr.com/?30sb7 。 Unlike Cornstalk's answer it does not capture anything, and
-
can indeed be placed later in a range if it's escaped. 与Cornstalk的答案不同,它不会捕获任何东西,而且
-
如果逃脱了,的确可以稍后放置在一定范围内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.