How can I separate enumerated block text to create an enumerated list using Find and Replace?

Hi,

I've been struggling with the following for hours and didn't get a working solution. I did get close using one expression and then another to tidy up the resulting text, but haven't managed to find a solution that I can apply to large amounts of text without creating lots of errors. I would appreciate anyone's help on this. I hope the following examples are clear to understand the problem?

Block Text Style (original text):

1 This is a mock text for using find and replace in Word. I need to separate text up that is enumerated, but in block text style. I want to make it into a list style. 2 I have tried using different codes, but none have worked so far. What I have used so far either removes the number or separates the text up into sentences. 3 I have a lot of text that I need to convert so this is a very repetitive task and it would be helpful to find a way of automating this task. 4. I would be grateful for any help to find a code for find and replace that can handle this task to convert this current format to the following list style.

Desired List Style (manually modified text):

1 This is a mock text for using find and replace in Word. I need to separate text up that is enumerated, but in block text style. I want to make it into a list style.
2 I have tried using different codes, but none have worked so far. What I have used so far either removes the number or separates the text up into sentences.
3 I have a lot of text that I need to convert so this is a very repetitive task and it would be helpful to find a way of automating this task.
4. I would be grateful for any help to find a code for find and replace that can handle this task to convert this current format to the following list style.

Current Find and Replace Attempt Produces Sentences (erroneous list style):

1 This is a mock text for using find and replace in Word.
I need to separate text up that is enumerated, but block text.
I want to make it into a list style.
2 I have tried using different codes, but none have worked so far.
What I have used so far either removes the number or separates the text up into sentences.
3 I have a lot of text that I need to convert so this is a very repetitive task and it would be helpful to find a way of automating this task.
4.
I would be grateful for any help to find a code for find and replace that can handle this task to convert this current format to the following list style.


I have tried using [0-99] or [0-9] which locates the individual numbers in the text and then ^| to get the manual line break. But, this eliminates the existing numbers leaving text with no enumeration. For the current example, I used .  (i.e. period plus space) to find the end of each numbered text and then .^| to create a manual line break, but as seen above this creates a list of separate sentences?! I then tried the expression: ^l[!0-9] to rejoin the phrases except where there is a number, but although this expression does find the manual line break and rejoin the phrases ignoring the numbered phrases, it eats the first letter of the rejoined phrases!

Appreciate the help,

John.

When doing a replace, if you want to keep the thing you found (the number) and add something before or after it, then the replacement expression must contain a code to tell Word to insert both items, not just the added item.

The code you need depends on whether you're doing an ordinary replace or a wildcard replace. I assume your lists might use numbers with two or more digits, so in that case a wildcard replace is appropriate. I also assume that you deliberately included a period after the 4 and not after the other numbers to imply that your items might be punctuated either way, another reason to use wildcards.

In the Replace dialog, click the More button and check the box for "Use wildcards". 

Click in the Find What box and enter the expression

(. )([0-9]{1,})

Then click in the Replace With box and enter the expression

\1^p\2

Click the Replace All button. That should create the desired text (assuming that there are no digits in the original text other than the item numbers).

The meaning of the expressions is this: In the Find What, the period and space are literal characters to be matched. The parentheses around them are treated as special markers, saying that the period and space constitute the first group. The part [0-9]{1,} will match any sequence of one or more consecutive digits, and the parentheses around it marks that as the second group. In the Replace With, the \1 indicates the first group in the matched text, the ^p is the code for the paragraph mark, and \2 indicates the second group.

For a full explanation of wildcard syntax, see http://www.gmayor.com/replace_using_wildcards.htm.

_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 262 Applies to: