Richard Herron
Richard Herron

Reputation: 10092

Sublime Text regex to remove line breaks from a selection?

I can't figure out the Sublime Text regex to remove line breaks from a selection.

The context is that I'm formatting a textbook test bank to generate a Blackboard quiz pool via an online Blackboard quiz generator. Here is an example question.  

25.   An increase in which of the following will increase the current value of a stock according to the dividend growth model?
I. dividend amount
II. number of future dividends, provided the current number is less than infinite
III. discount rate
IV. dividend growth rate 
A.    I and II only
B.    III and IV only
C.    I, II, and III only
*D.    I, II, and IV only
E.    I, II, III, and IV

I would like to remove the line breaks within the Roman numeral section so that the question is on one line with each answer (i.e., A through E) is on a separate line. Here is the desired output.  

25.   An increase in which of the following will increase the current value of a stock according to the dividend growth model? I. dividend amount II. number of future dividends, provided the current number is less than infinite III. discount rate IV. dividend growth rate 
A.    I and II only
B.    III and IV only
C.    I, II, and III only
*D.    I, II, and IV only
E.    I, II, III, and IV

This is easy enough on a case basis with CTRL-J, but I would like a scalable solution since some of these files are quite large. I am also using RegReplace to save time.

Is there a way to do this with Sublime Text regex? I can find the block with /^[0-9]{1,3}\..*?IV/s (I am using the dotall option in RegReplace to include line breaks in the .*), but I can't figure out how to remove the line breaks.

Upvotes: 1

Views: 918

Answers (1)

ndnenkov
ndnenkov

Reputation: 36101

I'll assume you don't get roman numbers > 99:

\n(?=[IVXL])

You match the new line, which is followed by one of I, V, X or L (but without matching the actual number). Replace with a space.

Upvotes: 2

Related Questions