[Cialug] Regular Expression Search & Replace Problem

Todd Walton tdwalton at gmail.com
Wed Jan 3 19:54:18 UTC 2018


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


More information about the Cialug mailing list