I am trying to parse some reStructuredTex开发者_如何学编程t and want to be able to identify when the indent level has changed. So, I need to be able to see when an indent of 8 spaces has changed to an indent of 4 spaces (for example), so that I can change the color of that text block. Is there a way of using regular expressions to count the number of spaces in the indent and pick out the next line that contains a shallower indent?
Something like this will work:
/
^(\s*)\S.*$ #Find a line with some number of spaces
(?:^\1\S.*$)* #Find more lines with the same starting spaces
^.*$ #This is the line you want here
/xm #x to ignore whitespace in the regex.
#m to have ^and $ match all lines
精彩评论