Regular Expression Fill-Down

Posted by richardtallent on Stack Overflow See other posts from Stack Overflow or by richardtallent
Published on 2010-04-14T22:32:16Z Indexed on 2010/04/14 22:43 UTC
Read the original article Hit count: 483

Filed under:
|
|

I have a plain text file something like this:

Ford\tTaurus
  F-150
  F-250
Toyota\tCamry
  Corsica

In other words, a two-level hierarchy where the first child is on the same line as the parent, but subsequent children on lines following, distinguished from being a parent by a two-space prefix (\t above represents a literal tab in the text).

I need to convert to this using RegEx:

Ford\tTaurus
Ford\tF-150
Ford\tF-250
Toyota\tCamry
Toyota\tCorsica

So, I need to capture the parent (text between \r\n and \t not starting with \s\s), and apply that in the middle of any \r\n\s\s found until the next parent.

I have a feeling this can be done with some sort of nested groups, but I think I need more caffeine or something, can't seem to work out the pattern.

(Using .NET with IgnoreWhitespace off and Multiline off)

© Stack Overflow or respective owner

Related posts about regex

Related posts about .NET