本文介绍了全局样式模式和正则表达式之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到过这样的情况,其中仅支持glob样式的模式,并且不提供完整的正则表达式支持,例如redis键.我想知道两者之间的区别.同样让我感到奇怪的是,与某些软件根本不支持regex的glob样式模式相比,实现regex匹配算法难吗?

I've encountered situations where only glob-style patterns are supported and full regular expression support is not there, for instance redis keys. I'd like to know the distinction between the two. Also it makes me wonder, is implementing regex matching algorithm way harder compared to glob-style pattern that some softwares doesn't support regex at all?

推荐答案

传统glob通配符支持非常窄的元字符集-*是任何内容",?是任意单个字符; Bourne Shell还支持[a-z123]表示一组替代字符中的单个字符,以及[!x-z789]除列出的那些字符之外的任何其他字符.

Traditional glob wildcards support a very narrow set of metacharacters — * is "anything", ? is an arbitrary single character; Bourne shell also supports [a-z123] for a single character out of a set of alternatives, and [!x-z789] any one except those listed.

正则表达式显然更丰富,支持重复,以及(在ERE中)交替和特定数量的重复. Perl风格的正则表达式将形式主义进一步扩展到写了多本书的地步,以后还会更多.

Regex obviously is much richer, supporting repetitions, and (in ERE) alternation and specific numbers of repetitions. Perl-style regex further extends the formalism to the point where multiple books have been written, and more will be.

基本的正则表达式在编程方面并没有比glob通配符更具挑战性,如今,无论如何,有能力的程序员无论哪种情况都可以链接到现有库.

Basic regex is not altogether a lot more challenging to program than glob wildcards, and these days, a competent programmer would link to an existing library in either case, anyway.

许多更简单的系统都不想让用户负担学习正则表达式的复杂性-即使是基本通配符,对于向非全职计算机用户的普通销售人员^ W ^ W人进行解释也是一个挑战.

Many simpler systems don't want to burden their users with the complexity of learning regular expressions — even basic wildcards are a challenge to explain to your average sales guy^W^W person who isn't a full-time computer user.

这篇关于全局样式模式和正则表达式之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 13:19