正则表达式

本文探讨了正则表达式的两种引擎类型:正则表达式导向引擎和文本导向引擎,并详细解释了它们的工作原理及特点。重点介绍了正则表达式导向引擎如何进行回溯以及如何控制这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

While there are many implementations of regular expressions that differ sometimes slightly and sometimes significantly in syntax(语法) and behavior, there are basically only two kinds of regular expression engines: text-directed engines, and regex-directed engines. Nearly all modern regex flavors are based on regex-directed engines. This is because certain very useful features, such as lazy quantifiers and backreferences, can only be implemented in regex-directed engines.

译文:

虽然有许多实现的正则表达式语法和行为有时略有不同,有时显着,基本上有正则表达式引擎只有两种:文本导向引擎,和正则表达式导向的引擎。几乎所有现代的正则表达式是基于正则表达式引擎。这是因为一些非常有用的功能,如量词和反向引用,只能在正则表达式的正则导向中实现。

A regex-directed engine walks through the regex, attempting to match the next token in the regex to the next character. If a match is found, the engine advances through the regex and the subject string. If a token fails to match, the engine backtracks to a previous position in the regex and the subject string where it can try a different path through the regex. This tutorial will talk a lot more about backtracking later on. Moderns regex flavors using regex-directed engines have lots of features such as atomic grouping and possessive quantifiers that allow you to control this backtracking.

遍历一个regex正则导向的正则表达式,试图匹配正则表达式中的下一个标记到下一个字符。如果找到一个匹配,引擎通过正则表达式和目标字符串的进步。如果令牌不匹配,引擎回溯到以前的位置在正则表达式的目标字符串中通过正则表达式,它可以尝试不同的路径。本教程将多谈了很多,关于回溯稍后。现代人正则表达式使用正则表达式定向引擎的口味有很多的功能,例如,使您可以控制这种回溯的原子分组和占有优先量词。

A text-directed engine walks through the subject string, attempting all permutations of the regex before advancing to the next character in the string. A text-directed engine never backtracks. Thus, there isn't much to discuss about the matching process of a text-directed engine. In most cases, a text-directed engine finds the same matches as a regex-directed engine.

文本导向的引擎走过的主题串,试图推进到下一个字符串中的字符前的正则表达式的所有排列。文本导向的引擎不会回溯。因此,没有太多的讨论文本定向引擎的匹配过程。在大多数情况下,文本引擎找到相同的匹配一个正则表达式定向发动机。

When this tutorial talks about regex engine internals, the discussion assumes a regex-directed engine. It only mentions text-directed engines in situations where they find different matches. And that only really happens when your regex uses alternation with two alternatives that can match at the same position.

当本教程中有关正则表达式引擎内部,讨论假设一个正则导向引擎。只提及文本引擎的情况下,他们发现不同的匹配。只有真正发生时,你的正则表达式使用交替有两种选择,可以在相同的位置相匹配。

This is a very important point to understand: a regex engine always returns the leftmost match, even if a "better" match could be found later. When applying a regex to a string, the engine start at the first character of the string. It tries all possible permutations of the regular expression at the first character. 

有一点非常重要:一个正则表达式引擎总是返回最左边的匹配,即使后来发现一个“更好”的匹配存在。当施加一个正则表达式字符串时,发动机启动的第一个字符的字符串。它会尝试所有可能的排列的正则表达式的第一个字符。

内容概要:本文介绍了奕斯伟科技集团基于RISC-V架构开发的EAM2011芯片及其应用研究。EAM2011是一款高性能实时控制芯片,支持160MHz主频和AI算法,符合汽车电子AEC-Q100 Grade 2和ASIL-B安全标准。文章详细描述了芯片的关键特性、配套软件开发套件(SDK)和集成开发环境(IDE),以及基于该芯片的ESWINEBP3901开发板的硬件资源和接口配置。文中提供了详细的代码示例,涵盖时钟配置、GPIO控制、ADC采样、CAN通信、PWM输出及RTOS任务创建等功能实现。此外,还介绍了硬件申领流程、技术资料获取渠道及开发建议,帮助开发者高效启动基于EAM2011芯片的开发工作。 适合人群:具备嵌入式系统开发经验的研发人员,特别是对RISC-V架构感兴趣的工程师和技术爱好者。 使用场景及目标:①了解EAM2011芯片的特性和应用场景,如智能汽车、智能家居和工业控制;②掌握基于EAM2011芯片的开发板和芯片的硬件资源和接口配置;③学习如何实现基本的外设驱动,如GPIO、ADC、CAN、PWM等;④通过RTOS任务创建示例,理解多任务处理和实时系统的实现。 其他说明:开发者可以根据实际需求扩展这些基础功能。建议优先掌握《EAM2011参考手册》中的关键外设寄存器配置方法,这对底层驱动开发至关重要。同时,注意硬件申领的时效性和替代方案,确保开发工作的顺利进行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值