如何编写正则表达式以使字符串结尾处带有冒号 [英] How to write a regular expression to match a string with colon at the end

查看:651
本文介绍了如何编写正则表达式以使字符串结尾处带有冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



[0-9a-zA-z]:

此正则表达式用于验证带有一个字符或数字并在末尾加冒号的字符串.

例如:1 :, a :, c:

我该如何重写此正则表达式以适应任何否.冒号前面的字符/数字的符号(:).


在此先谢谢您.

Hi,

[0-9a-zA-z]:

This regular expression is for validating a string with one charecter or number and a colon at the end.

For Eg: 1:, a:, c:

How can I rewrite this regualr expression to accomodate any no. of charecter/ numbers infront of the colon (:).


Thanks in advance.

推荐答案

都可以
[0-9a-zA-Z]+:

表示一个或多个",或者

for "one or more", or

[0-9a-zA-Z]*:

用于零个或多个"
但是您可能会发现更好的方法:

for "zero or more"
But you may find this better:

\w+:

表示一个或多个",或者

for "one or more", or

\w*:

表示零个或多个"

"\ w"等同于"[0-9a-zA-Z _]"

for "zero or more"

"\w" is the equivalent of "[0-9a-zA-Z_]"


这篇关于如何编写正则表达式以使字符串结尾处带有冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆