Find and remove parenthesis

T

Tammy

Hello,

I have years listed in a document as:
(2007)
and would like to remove all of the parenthesis surrounding the year. So,
the year should then display as:
2007
There are possibly hundreds of these to change, so I'm looking for an easy
way of doing this.

I know I can have the Find and Replace dialog box find the open parenthesis,
and replace it with nothing. Then, I can run through the same process for all
closing parentheses. But, again, this could take a long time, as there may be
hundreds of parentheses.

There is other text within the document that is enclosed within parentheses,
and I do not want it included in the find.

I've also tried working with the wildcard option. I found the year
surrounded by parens by typing:
\(????\)
However, I can't figure out what to put in the Replace field. I want to
replace with just the numbers.

I'm using Word 2007.

Any suggestions? Thank you!
 
J

Jay Freedman

Hello,

I have years listed in a document as:
(2007)
and would like to remove all of the parenthesis surrounding the year. So,
the year should then display as:
2007
There are possibly hundreds of these to change, so I'm looking for an easy
way of doing this.

I know I can have the Find and Replace dialog box find the open parenthesis,
and replace it with nothing. Then, I can run through the same process for all
closing parentheses. But, again, this could take a long time, as there may be
hundreds of parentheses.

There is other text within the document that is enclosed within parentheses,
and I do not want it included in the find.

I've also tried working with the wildcard option. I found the year
surrounded by parens by typing:
\(????\)
However, I can't figure out what to put in the Replace field. I want to
replace with just the numbers.

I'm using Word 2007.

Any suggestions? Thank you!

You're on the right track with the wildcard replacement. You now need to add
some things to it to preserve the numbers.

In a wildcard search expression you can enclose things in parentheses _without_
the backslashes to indicate a group:

\((????)\)

Then the replace expression can refer to that group as

\1

If you had more groups in the search expression, they would be \2, \3 and so on.

This is explained in more detail at
http://www.gmayor.com/replace_using_wildcards.htm.
 
J

Jean-Guy Marcil

Tammy said:
Hello,

I have years listed in a document as:
(2007)
and would like to remove all of the parenthesis surrounding the year. So,
the year should then display as:
2007
There are possibly hundreds of these to change, so I'm looking for an easy
way of doing this.

I know I can have the Find and Replace dialog box find the open parenthesis,
and replace it with nothing. Then, I can run through the same process for all
closing parentheses. But, again, this could take a long time, as there may be
hundreds of parentheses.

There is other text within the document that is enclosed within parentheses,
and I do not want it included in the find.

I've also tried working with the wildcard option. I found the year
surrounded by parens by typing:
\(????\)
However, I can't figure out what to put in the Replace field. I want to
replace with just the numbers.

Almost there...!

In the "Find what" part, use:
\((????)\)
In "Replace with" use:
\1

"\1" tells Word to keep intact whatever is in between the first set of ( )
in the "Find what" part. You could have many sets of ( ). Each set would be
numbered in the order they appear \1 \2 \3. You can use that to switch
strings of text around [Find (Bo???)( Smit???) and Replace with \2\1, etc.],
delete only certain parts [Find (Bo???)( Smit???) and Replace with \2, etc.],
etc...
In your case, since the the ( ) in the text are not part of the ( ) in the
code expression in the "Find what" part, they will be deleted. "\(" tells
Word that the "(" following the "\" is an actual "(", not a opening
parenthesis for a string of text used as a wild card code, like the second
"(" in the expression.
 
T

Tammy

Hi Jean-Guy,

Thank you so much for the solution and the explanation! It works perfectly!
I truly appreciate you responding to my post!

Have a great day!

Jean-Guy Marcil said:
Tammy said:
Hello,

I have years listed in a document as:
(2007)
and would like to remove all of the parenthesis surrounding the year. So,
the year should then display as:
2007
There are possibly hundreds of these to change, so I'm looking for an easy
way of doing this.

I know I can have the Find and Replace dialog box find the open parenthesis,
and replace it with nothing. Then, I can run through the same process for all
closing parentheses. But, again, this could take a long time, as there may be
hundreds of parentheses.

There is other text within the document that is enclosed within parentheses,
and I do not want it included in the find.

I've also tried working with the wildcard option. I found the year
surrounded by parens by typing:
\(????\)
However, I can't figure out what to put in the Replace field. I want to
replace with just the numbers.

Almost there...!

In the "Find what" part, use:
\((????)\)
In "Replace with" use:
\1

"\1" tells Word to keep intact whatever is in between the first set of ( )
in the "Find what" part. You could have many sets of ( ). Each set would be
numbered in the order they appear \1 \2 \3. You can use that to switch
strings of text around [Find (Bo???)( Smit???) and Replace with \2\1, etc.],
delete only certain parts [Find (Bo???)( Smit???) and Replace with \2, etc.],
etc...
In your case, since the the ( ) in the text are not part of the ( ) in the
code expression in the "Find what" part, they will be deleted. "\(" tells
Word that the "(" following the "\" is an actual "(", not a opening
parenthesis for a string of text used as a wild card code, like the second
"(" in the expression.
 

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