The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,373 other followers

Convert space indented text to markdown minus indented

Posted by jpluimers on 2018/01/17

Since I will never be good at regex, this are a few search/replace patterns I used in Atom.io to convert a plain text document space indented like this:

Version 1.23.4.15
First level indented text
Is also a first level indented text
Too a first level indented text
- First level indented text too
  Second level indented text
  Is also a second level indented text
  Too a second level indented text
  - Second level indented text too
    - A third level indented text
    Third level indented text
    Is also a third level indented text
    Too a third level indented text
98.4.32.1

to a Markdown indented one like this:

Version 1.23.4.15
- First level indented text
- Is also a first level indented text
- Too a first level indented text
- First level indented text too
 - Second level indented text
 - Is also a second level indented text
 - Too a second level indented text
 - Second level indented text too
 - A third level indented text
 - Third level indented text
 - Is also a third level indented text
 - Too a third level indented text
Version 98.4.32.1

Prepend Version when needed: https://regex101.com/r/CUhUbr/1

  • Search:
    • ^(\d+\.\d+\.\d+\.\d+)
  • Replace:
    • Version $1

Add markdown first level indentations to lines that don’t have a markdown first level indentation yet, nor start with Version nor start with a space: https://regex101.com/r/CUhUbr/2

  • Search:
    • ^(?!(Version )|(- )|( )|(\d+\.\d+\.\d+\.\d+))(.*)
  • Replace:
    • - $5

Add markdown second level indentations to lines that don’t have a markdown second level indentation yet but do have a regular second level indentation: https://regex101.com/r/CUhUbr/3

  • Search:
    • ^  (?!(- )|( ))(.*)
  • Replace:
    •   - $3

Add markdown third level indentations to lines that don’t have a markdown third level indentation yet but do have a regular third level indentation: https://regex101.com/r/CUhUbr/4

  • Search:
    • ^    (?!(- )|( ))(.*)
  • Replace:
    •     - $3

jeroen

https://regex101.com/r/CUhUbr/1

https://regex101.com/r/CUhUbr/2

https://regex101.com/r/CUhUbr/3

https://regex101.com/r/CUhUbr/4

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

 
%d bloggers like this: