*和.*在正则表达式中有什么区别? [英] What's the difference between * and .* in regular expressions?

查看:102
本文介绍了*和.*在正则表达式中有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到*的通配符在某些命令中使用,例如:find *.jpg,这意味着找到以.jpg结尾的任何文件.但是,在正则表达式中,.*也表示任何字符0次或多次.那么,它们之间有什么区别?何时使用*,何时使用.*?

I saw the wildcard of * been used in some command like: find *.jpg, which means find any files ended with .jpg. However, in regular expressions, .* also means that 0 or more times for any character. So, what's the difference between them? When is * been used and when is .*?

推荐答案

在正则表达式中,*是零个或多个"重复标记. .是任何单个字符(带有警告)"表达.

In regular expressions, * is the "zero or more" repetition marker. . is the "any single character (with caveats)" expression.

find中,*字符是任何内容"通配符,并不是真正的正则表达式字符. ?是这种搜索情况下的任何单个字符".

In a find the * character is an "anything" wildcard and is not really a regular expression character. The ? is the "any single character" in search situations of this kind.

这篇关于*和.*在正则表达式中有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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