块缩进正则表达式
我遇到了关于正则表达式的问题。
我正在尝试实现一个正则表达式来仅选择制表符缩进块,但我找不到使其工作的方法:
示例:
INDENT(1)
INDENT(2)
CONTENT(a)
CONTENT(b)
INDENT(3)
CONTENT(c)
所以我需要如下块:
INDENT(2)
CONTENT(a)
CONTENT(b)
AND
INDENT(3)
CONTENT(c)
我怎样才能做到这一点?
真的谢谢,几乎就是这样,这是我最初的需求:
table
tr
td
"joao"
"joao"
td
"marcos"
我需要分隔的“td”块,我可以调整你的示例吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全取决于您想要做什么,但也许是这样的:
工作示例: http://www .rubular.com/r/qj3WSWK9JR
该模式搜索:
^(\t+)(\S.*)\n
- 以制表符开头的行(我也捕获第一行一组,只是为了看看效果),然后是(?:\1\t.*\n)*
- 带有更多选项卡的行。同样,您可以使用
^( +)(\S.*)\n(?:\1 .*\n)*
表示空格 (示例)。不过,混合使用空格和制表符可能会有点问题。对于更新后的问题,请考虑使用
^(\t{2,})(\S.*)\n(?:\1\t.*\n)*
,至少 2 个选项卡在该行的开头。It depends on exactly what you are trying to do, but maybe something like this:
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.您可以使用以下正则表达式来获取组...
这要求您的行不能以块开头的空格开头。
You could use the following regex to get the groups...
this requires that your lines not begin with white space for the beginning of the blocks.