[Cialug] Regular Expression Search & Replace Problem

Scott Yates Scott at yatesframe.com
Wed Jan 3 20:19:12 UTC 2018


Ya, this seems like something that really is not suited to regex.  I am
sure there is a way to make it work, but it is likely easier with a little
python script.

On Wed, Jan 3, 2018 at 2:16 PM, Adam Hill <adam at diginc.us> wrote:

> Multi-line regex are always a pain.  There's probably some linux one liner
> that would implement the logic to do this but it'd be more readable in
> something like python.
>
> On Wed, Jan 3, 2018 at 1:55 PM Todd Walton <tdwalton at gmail.com> wrote:
>
> > If I had a text file loaded in an editor with PCRE regular expression
> > matching, how would I search & replace this:
> >
> >     Mr.
> >           John Williams
> >           Dan Kathney
> >           Elmo Tickled
> >
> >     Ms.
> >           Linda Tenner
> >           Sam Renkl
> >           Matilda Geunse
> >
> >     Dr.
> >           Andy Hathaway
> >           Diane Seaton
> >           Fran Francis
> >
> > into this?:
> >
> >     Mr.      John Williams
> >     Mr.      Dan Kathney
> >     Mr.      Elmo Tickled
> >
> >     Ms.      Linda Tenner
> >     Ms.      Sam Renkl
> >     Ms.      Matilda Geunse
> >
> >     Dr.      Andy Hathaway
> >     Dr.      Diane Seaton
> >     Dr.      Fran Francis
> >
> > Note, those are all spaces, and all indents are the same number of
> spaces.
> > Also, I don't care about the spacing in the output, just that the titles
> > end up on the same line as the names.
> >
> > So if, say, the indents are four and eight spaces, then something like
> "if
> > four spaces followed by <title> followed by newline followed by eight
> > spaces and a <name> then newline, replace it all with <title> space
> <name>
> > newline". But you'd have to take account of the multiple name lines below
> > each title line. Maybe match "four spaces <title> newline eight spaces
> > <name> newline eight spaces <name> newline eight spaces <name> newline,
> > replace each occurrence of eight spaces in the match with the <title>".
> >
> > Or something.
> >
> > -Todd
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
> >
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>


More information about the Cialug mailing list