Rreplace first space in each paragraph with a tab character (2007)

S

Sesquipedalian Sam

I have a large text file that I imported into Word. It is a list of
items followed by explanations. The Items are all a single word.

Is there a replace string that will replace only the first space
character in each paragraph with a tab character?
 
J

Jay Freedman

With "Use wildcards" turned on, enter the search term

([! ]@) ([!^13]@^13)

and the replacement term

\1^t\2

In the search term, there is a space character after the first exclamation mark, and another after the first closing parenthesis.

Explanation: The expression in the first pair of parentheses of the search term means "one or more characters that are not spaces", and that corresponds to the \1 in the replacement term.
The expression in the second pair of parentheses means "one or more characters that are not paragraph marks, followed by one paragraph mark", and that becomes the \2 in the replacement.
The space character between the two sets of parentheses is replaced by the ^t (a tab character).
 
S

Sesquipedalian Sam

With "Use wildcards" turned on, enter the search term

([! ]@) ([!^13]@^13)

and the replacement term

\1^t\2

In the search term, there is a space character after the first exclamation mark, and another after the first closing parenthesis.

Explanation: The expression in the first pair of parentheses of the search term means "one or more characters that are not spaces", and that corresponds to the \1 in the replacement term.
The expression in the second pair of parentheses means "one or more characters that are not paragraph marks, followed by one paragraph mark", and that becomes the \2 in the replacement.
The space character between the two sets of parentheses is replaced by the ^t (a tab character).

That worked perfectly. I would have never figured that one out.

I ended up deciding to replace the first 2 spaces with tabs. I started
to see if I could write the expression to do it, when I realized that
I could simply run this one twice.

I'm guessing that a single expression to do that would involve
inserting one more "term" in between the ones you have now, maybe
something like this:

([! ]@) ([! ]@) ([!^13]@^13)

and the replacement term would be

\1^t\2^t\3

Is that correct?

Is there any limit to the number of terms?

Thank you very much.
 
S

Sesquipedalian Sam

With "Use wildcards" turned on, enter the search term

([! ]@) ([!^13]@^13)

and the replacement term

\1^t\2

In the search term, there is a space character after the first exclamation mark, and another after the first closing parenthesis.

Explanation: The expression in the first pair of parentheses of the search term means "one or more characters that are not spaces", and that corresponds to the \1 in the replacement term.
The expression in the second pair of parentheses means "one or more characters that are not paragraph marks, followed by one paragraph mark", and that becomes the \2 in the replacement.
The space character between the two sets of parentheses is replaced by the ^t (a tab character).

PS: Why did you use "^13" instead of "^p"?
 
S

Suzanne S. Barnhill

Because ^p is not a valid search term when using wildcards. To make matters
worse, if you click "Special" for the "Find what" box when "Use wildcards"
is checked, you won't even see an entry for "paragraph mark." ^13 is just
one of those things you have to know. For more, see
http://www.gmayor.com/replace_using_wildcards.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Sesquipedalian Sam said:
With "Use wildcards" turned on, enter the search term

([! ]@) ([!^13]@^13)

and the replacement term

\1^t\2

In the search term, there is a space character after the first exclamation
mark, and another after the first closing parenthesis.

Explanation: The expression in the first pair of parentheses of the search
term means "one or more characters that are not spaces", and that
corresponds to the \1 in the replacement term.
The expression in the second pair of parentheses means "one or more
characters that are not paragraph marks, followed by one paragraph mark",
and that becomes the \2 in the replacement.
The space character between the two sets of parentheses is replaced by the
^t (a tab character).

PS: Why did you use "^13" instead of "^p"?
 
S

Sesquipedalian Sam

Because ^p is not a valid search term when using wildcards. To make matters
worse, if you click "Special" for the "Find what" box when "Use wildcards"
is checked, you won't even see an entry for "paragraph mark." ^13 is just
one of those things you have to know. For more, see
http://www.gmayor.com/replace_using_wildcards.htm

Amazing. This is one of their flagship products. How can they continue
to sell junk like this? This type of patchwork software was
understandable in 1960. This is 2010. Amazing.
 
S

Sesquipedalian Sam

With "Use wildcards" turned on, enter the search term

([! ]@) ([!^13]@^13)

and the replacement term

\1^t\2

In the search term, there is a space character after the first exclamation mark, and another after the first closing parenthesis.

Explanation: The expression in the first pair of parentheses of the search term means "one or more characters that are not spaces", and that corresponds to the \1 in the replacement term.
The expression in the second pair of parentheses means "one or more characters that are not paragraph marks, followed by one paragraph mark", and that becomes the \2 in the replacement.
The space character between the two sets of parentheses is replaced by the ^t (a tab character).

I just wanted to thank you for this tip and explanation. It just saved
me several hours or manual editing or even longer trying to debug a
macro.

Many thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top