块缩进正则表达式 [英] Block Indent Regex
问题描述
我在使用正则表达式时遇到问题.
我正在尝试实现一个正则表达式来只选择选项卡缩进块,但我找不到让它工作的方法:
示例:
INDENT(1)缩进(2)内容(一)内容(b)缩进(3)内容(c)
所以我需要这样的块:
INDENT(2)内容(一)内容(b)
AND
INDENT(3)内容(c)
我该怎么做?
<小时>真的很不错,差不多就是这样,这是我最初的需求:
表trtd若昂"若昂"td马科斯"
我需要单独的td"块,我可以调整你的例子吗?
<小时>这取决于你想要做什么,但可能是这样的:
^(\t+)(\S.*)\n(?:\1\t.*\n)*
工作示例:http://www.rubular.com/r/qj3WSWK9JR>
模式搜索:
^(\t+)(\S.*)\n
- 以制表符开头的一行(我也捕获了组中的第一行,只是为了看看效果), 其次是(?:\1\t.*\n)*
- 带有更多标签的行.
同样,您可以使用 ^( +)(\S.*)\n(?:\1 .*\n)*
表示空格(示例).不过,混合使用空格和制表符可能会有点问题.
对于更新的问题,考虑使用 ^(\t{2,})(\S.*)\n(?:\1\t.*\n)*
,对于 at行首至少有 2 个标签.
I'm having problems about a regexp.
I'm trying to implement a regex to select just the tab indent blocks, but i cant find a way of make it work:
Example:
INDENT(1)
INDENT(2)
CONTENT(a)
CONTENT(b)
INDENT(3)
CONTENT(c)
So I need blocks like:
INDENT(2)
CONTENT(a)
CONTENT(b)
AND
INDENT(3)
CONTENT(c)
How I can do this?
really tks, its almost that, here is my original need:
table
tr
td
"joao"
"joao"
td
"marcos"
I need separated "td" blocks, could i adapt your example to that?
It depends on exactly what you are trying to do, but maybe something like this:
^(\t+)(\S.*)\n(?:\1\t.*\n)*
Working example: http://www.rubular.com/r/qj3WSWK9JR
The pattern searches for:
^(\t+)(\S.*)\n
- a line that begins with a tab (I've also captured the first line in a group, just to see the effect), followed by(?:\1\t.*\n)*
- lines with more tabs.
Similarly, you can use ^( +)(\S.*)\n(?:\1 .*\n)*
for spaces (example). Mixing spaces and tabs may be a little problematic though.
For the updated question, consider using ^(\t{2,})(\S.*)\n(?:\1\t.*\n)*
, for at least 2 tabs at the beginning of the line.
这篇关于块缩进正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!