.*(点星)如何工作? [英] How .* (dot star) works?

查看:45
本文介绍了.*(点星)如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经明白 .* 意味着零个或多个任何字符,但是有人能解释一下 .* 在下面的工作中是如何工作的以及它会匹配什么吗?

I already understand that .* means zero or more of any character, but Could someone explain how .* in the following work and what it would match?

.*([a-m/]*).*

.*([a-m/]+).*

.*?([a-m/]*).*

推荐答案

每个案例都不同:

.*([a-m\/]*).*

第一个 .* 可能会匹配整个字符串,因为 [am/] 不需要出现,第一个 *> 贪婪且优先.

The first .* will probably match the whole string, because [a-m/] is not required to be present, and the first * is greedy and comes first.

.*([a-m\/]+).*

第一个 .* 将匹配整个字符串直到匹配 [am/] 的最后一个字符,因为只需要一个,第一个 * 贪婪且先到.

The first .* will match the whole string up to the last character that matches [a-m/] since only one is required, and the first * is greedy and comes first.

.*?([a-m\/]*).*

第一个 .*? 将匹配字符串直到匹配 [am/] 的第一个字符,因为 *? 不是贪婪,那么 [am/]* 将匹配所有它可以匹配的,因为 * 是贪婪的,然后最后一个 .* 将匹配其余的的字符串.

The first .*? will match the string up to the FIRST character that matches [a-m/], because *? is not greedy, then [a-m/]* will match all it can, because * is greedy, and then the last .* will match the rest of the string.

这篇关于.*(点星)如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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