I'm fairly happy most of the time using REs and can come up with some hairy looking stuff occasionally but I can't, at the moment, see a way to do this:-
I want to match two lines like the following using a Regular Expression:-
abcmnoxyz =========
The first line is essentially random, the second line will be all the same character of a limited number of possibles (=, - and maybe a couple more). The lines can probably be required to be the same length but it would be nice if they didn't have to be. It would be OK to have multiple REs, one for each possible 'underline' character.
It's not a fixed length by the way, the minimum length will probably be 4 characters or so.
Can anyone come up with a way to do this?
-------- Original Message -------- The first line is essentially random, the second line will be all the same character of a limited number of possibles (=, - and maybe a couple more). The lines can probably be required to be the same length but it would be nice if they didn't have to be. It would be OK to have multiple REs, one for each possible 'underline' character.
Context is everything. Why are you trying to do this with a regular expression and what implementation will you be using?
Something like /([-_=])\1{3,}/ will match the underline part (the rest is straightforward) in some implementations but not all allow you to use backrefs in the match.
/.{4,}\n([-_=])\1{3,}/ ought to match what you've described. Again... it depends ;)
Steve
On Mon, Oct 30, 2017 at 05:26:33AM -0400, Steve Engledow wrote:
-------- Original Message -------- The first line is essentially random, the second line will be all the same character of a limited number of possibles (=, - and maybe a couple more). The lines can probably be required to be the same length but it would be nice if they didn't have to be. It would be OK to have multiple REs, one for each possible 'underline' character.
Context is everything. Why are you trying to do this with a regular expression and what implementation will you be using?
Something like /([-_=])\1{3,}/ will match the underline part (the rest is straightforward) in some implementations but not all allow you to use backrefs in the match.
/.{4,}\n([-_=])\1{3,}/ ought to match what you've described. Again... it depends ;)
It's in PHP (ugh they say!).
I'm writing a plugin for DokuWiki so that it will recognise RestructuredText style underlined headings. The one thing I don't like about DokuWiki syntax is the heading style:-
======Top Level Heading======
====Lesser Heading====
I find restructuredText much more natural (and understandable when reading the text):-
Top Level Heading =================
Lesser Heading --------------
I have come up with a rather cruder RE than yours:-
'(?U)^[^\n]*\n====*$'
Obviously only matches ==== underlines but the way that DokuWiki plugins work means I can add multiple matching RE patterns so I can just repeat the above for other characters.
In yours does the range [-_=] mean it will match a line like ==-___===?
-------- Original Message -------- I'm writing a plugin for DokuWiki so that it will recognise RestructuredText style underlined headings.
With reference to threevirtues.com: https://www.dokuwiki.org/plugin:rst
:)
Steve
On Mon, Oct 30, 2017 at 07:17:02AM -0400, Steve Engledow wrote:
-------- Original Message -------- I'm writing a plugin for DokuWiki so that it will recognise RestructuredText style underlined headings.
With reference to threevirtues.com: https://www.dokuwiki.org/plugin:rst
Yes, I wrote that too, it's the only one I have written that I thought was good (and stable) enough to put on the DokuWiki site.
But my *new* plugin just adds restructuredText underline headings to otherwise standard DokuWiki markup, that's the point. I use DokuWiki so much that it has become second nature and I actually prefer its markup to restructuredText for some things. Adding the underline headings just means that I can have what (to me) is even more readable than standard DokuWiki markup.
I have some large chunks of (mainly older) notes and documentation that are in restructuredText, for those I can use the rst plugin, but for 'everyday' use now I can just write DokuWiki with nice headings! :-)