本文介绍了匹配Lua的“长括号"字符串语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Lua编写jFlex lexer,但在设计正则表达式以匹配语言规范的特定部分时遇到了问题:

I'm writing a jFlex lexer for Lua, and I'm having problems designing a regular expression to match one particular part of the language specification:

简而言之,我正在尝试设计一个正则表达式,该表达式将匹配长括号,中间的字符串内容和长括号.仅当长括号和右括号的等号个数相同(可以为零或更大)时,才发生匹配.

In a nutshell, I am trying to design a regular expression that will match an opening long bracket, the string contents in between, and the closing long bracket. A match should only occur when the opening long bracket and closing long bracket have the same number of equal signs, which can be zero or more.

推荐答案

\[(=*)\[.*?\]\1\]

\ 1捕获第一个().

the \1 captures the first ().

这篇关于匹配Lua的“长括号"字符串语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:49