removing parenthesis

2,426 views
Skip to first unread message

kurtz.kevin

unread,
Jun 6, 2011, 2:55:39 PM6/6/11
to TextWrangler Talk

I am not a programmer... I am just trying to remove all the instances
of parenthesis in my text. I have text that is littered with all
variations of parenthesis that I must remove.

How can textwrangler use a wildcard to find opening+anything+closing
parenthesis and delete every instance

for example...
"and the goat said to the frog (jn.3:1) that the worst..."
"in the historical instance of placards (da carson, bigtitle, p.387)
the..."

I just want all these parenthesis-es removed.

Please help!

Christopher Bort

unread,
Jun 7, 2011, 1:48:15 AM6/7/11
to textwr...@googlegroups.com
On 6/6/11 at 11:55 AM, kurtz...@gmail.com (kurtz.kevin) wrote:

>I am not a programmer... I am just trying to remove all the instances
>of parenthesis in my text. I have text that is littered with all
>variations of parenthesis that I must remove.
>
>How can textwrangler use a wildcard to find opening+anything+closing
>parenthesis and delete every instance

Do you want to just remove the actual parenthesis characters, or
the text between them as well?

>for example...
>"and the goat said to the frog (jn.3:1) that the worst..."
>"in the historical instance of placards (da carson, bigtitle, p.387)
>the..."
>
>I just want all these parenthesis-es removed.

The 'give a man a fish' answer:

Assuming that you want to delete the text between open and close
parens, do a Find (Search -> Find...) and enable the Grep
checkbox in the Find dialog. In the Find box, enter

\(.*\)

Leave the Replace box empty (i.e. replace with an empty string).
Click Replace All. Depending on your exact needs, you might need
to adjust it, but this is the quick and dirty solution.

The 'teach a man to fish' answer:

Read the chapter in the TW user manual on Searching With GREP.
Learn it. Know it. Love it. 8^)
--
Christopher Bort
<top...@thehundredacre.net>

Thomas Fischer

unread,
Jun 7, 2011, 4:43:56 AM6/7/11
to textwr...@googlegroups.com
Hi Kevin,


> Assuming that you want to delete the text between open and close parens, do a Find (Search -> Find...) and enable the Grep checkbox in the Find dialog. In the Find box, enter
>
> \(.*\)
>
> Leave the Replace box empty (i.e. replace with an empty string). Click Replace All. Depending on your exact needs, you might need to adjust it, but this is the quick and dirty solution.

This may not be quite what you want, because it will gobble up everything on a line between ( and ).
To get rid only of the parentheses and their contents you should use a "non-greedy" search: replace \(.*?\) with empty using grep.
If those parentheses are stretching over line boundaries, you might use \([^)]*\).
If you have nested parentheses, you have to use a more complicated approach...

> The 'teach a man to fish' answer:
>
> Read the chapter in the TW user manual on Searching With GREP. Learn it. Know it. Love it. 8^)

Here I fully agree!

Thomas

kurtz.kevin

unread,
Jun 7, 2011, 9:41:17 PM6/7/11
to TextWrangler Talk
<grin> thanks for the fishing lesson.

On Jun 7, 1:48 am, Christopher Bort <top...@thehundredacre.net> wrote:

Thomas Fischer

unread,
Mar 29, 2012, 2:11:43 AM3/29/12
to textwr...@googlegroups.com
Hi Hannes,

I'm not quite sure what you want to accomplish. Basically, the search you're looking for should be
\[[^\]]*\]
(with [^\]] not [^\)], because you're looking for a closing ]).
But if you have examples where the brackets are not closed properly, or if brackets are nested within each other, you have to decide what that means and what you have to do.

Best
Tomas

> Hey guys!
>
> I'm quite a novice with textwrangler and need it only for an empirical
> paper. I got textfiles that contain the 20 first post of a thread in a
> forum. I put instances of advice between [ ]. What I need now is a
> grep search that gives me all the instances of [abcd] in these
> textfiles:
>
> first time sex is always embarising and over way quicker than you want
> it to be. i remember my
> testerone at your age i wanted to rut with every female on the planet!
> then when i had sex for the
> first time when i was 19 i was like a shark on a leash it was no
> wonder i pre-came and it was over
> within 5 minutes! next time you have [goto the toilet before you get
> intermit don't smoke and
> definately dont drink both these give you "brewers droop".]
>
> to review
> [1. relax
> 2. no smoking or drinking
> 3. visit the toilet before sex
> 4. have fun!]
>
> 04-10-2007 09:13 PM
>
> Re: First time having sex, cannot last long at all.
>
> [I think masturbation is the key.] If my husband hasn't been
> masturbating enough, he usually finishes
> quickly when we have sex, especially if we haven't done it for awhile.
>
> So for this passage, search results should find 3 instances of advice
> (e.g., [advice]). What it actually does, using the modified grep
> search from Thomas, \[[^)]*\], is giving me the whole passage between
> the first [ and the last ] as one single instance. How can I get to
> three?
>
> Thanks for your help!
>
> Best,
> loeffeli


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescr...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/applescript-users/fischer.th%40aon.at
Archives: http://lists.apple.com/archives/applescript-users

This email sent to fisch...@aon.at

Hannes von Wyl

unread,
Mar 29, 2012, 9:11:11 AM3/29/12
to textwr...@googlegroups.com
Dear Tomas

Thanks a lot for your help, that did it! Roy just forgot to change the ) to ], and I don't have any clue about the search syntax. Could you tell me please how I would search for all the lines beginning with a *?

Best
Hannes


--
You received this message because you are subscribed to the
"TextWrangler Talk" discussion group on Google Groups.
To post to this group, send email to textwr...@googlegroups.com
To unsubscribe from this group, send email to
textwrangler...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/textwrangler?hl=en
If you have a feature request or would like to report a problem,
please email "sup...@barebones.com" rather than posting to the group.

Roy McCoy

unread,
Mar 29, 2012, 11:15:37 AM3/29/12
to textwr...@googlegroups.com
Hannes von Wyl wrote:

> Could you tell me please how I would search for all the lines beginning with a *?

^\*


Roy

Hannes von Wyl

unread,
Mar 29, 2012, 11:28:32 AM3/29/12
to textwr...@googlegroups.com
Thanks again!

Thomas Humiston

unread,
Mar 29, 2012, 4:54:48 PM3/29/12
to textwr...@googlegroups.com
Hannes, here's a breakdown. In a search pattern:

1. xyz = find xyz --anywhere within a line
2. ^xyz = find xyz --but only at the beginning of a line
3. [xyz] = find x OR y OR z --but NOT ] or [, of course
4. [^xyz] = find anything that's NOT x or y or z
5. [^xzy]* = find a run of characters that doesn't include x, y, or z

Notice that the addition of ^ means either "start of line" OR "none of
the following", depending on where the ^ is placed. Notice also that
the brackets above are used for grouping, and not as part of the
match. Therefore to find ] itself we add a backslash:

6. \] = find ]

Putting these together, one at a time:

\] = find a bracket
[^\]] = find NOT a bracket (i.e. anything else)
[^\]]* = find any number of not-brackets
\[[^\]]*\] = find [ plus some not-brackets plus ]

This pattern is a little tricky to understand because it uses brackets
in two different ways: for grouping AND to match a literal right-
bracket. Replacing \] with x allows one to more easily see the
structure:

x[^x]*x

In other words, we're looking for x, followed by any amount of "not
x", followed by x.

And now to your second question. Since, like square brackets, the
asterisk has a special meaning in Grep, finding it requires a backslash:

\*

And so we apply what we learned above to find it at the beginning of a
line:

^\*

I hope this helps.
- TH

Hannes von Wyl

unread,
Mar 30, 2012, 3:45:38 AM3/30/12
to textwr...@googlegroups.com
Dear Thomas

Thanks again for your help. Your breakdown made it much clearer than the manual ever could. I think I'm pretty well equipped now for the rest of my paper. Still, If I run into some difficulties again, I know I can count on you guys.

Best
Hannes

On Thu, Mar 29, 2012 at 10:54 PM, Thomas Humiston <t...@jumpingrock.net> wrote:
Hannes, here's a breakdown. In a search pattern:

1. xyz = find xyz --anywhere within a line
2. ^xyz = find xyz --but only at the beginning of a line
3. [xyz] = find x OR y OR z --but NOT ] or [, of course
4. [^xyz] = find anything that's NOT x or y or z
5. [^xzy]* = find a run of characters that doesn't include x, y, or z

Notice that the addition of ^ means either "start of line" OR "none of the following", depending on where the ^ is placed. Notice also that the brackets above are used for grouping, and not as part of the match. Therefore to find ] itself we add a backslash:

6. \] = find ]

Putting these together, one at a time:

 \] = find a bracket
 [^\]] = find NOT a bracket (i.e. anything else)
 [^\]]* = find any number of not-brackets
 \[[^\]]*\] = find [ plus some not-brackets plus ]

This pattern is a little tricky to understand because it uses brackets in two different ways: for grouping AND to match a literal right-bracket. Replacing \] with x allows one to more easily see the structure:
AppleScript-Users mailing list      (applescript-users@lists.apple.com)

Help/Unsubscribe/Update your Subscription:

https://lists.apple.com/mailman/options/applescript-users/fischer.th%40aon.at
Archives: http://lists.apple.com/archives/applescript-users

This email sent to fisch...@aon.at

--
You received this message because you are subscribed to the
"TextWrangler Talk" discussion group on Google Groups.
To post to this group, send email to textwr...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/textwrangler?hl=en
If you have a feature request or would like to report a problem,
please email "sup...@barebones.com" rather than posting to the group.

--
You received this message because you are subscribed to the
"TextWrangler Talk" discussion group on Google Groups.
To post to this group, send email to textwr...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/textwrangler?hl=en
If you have a feature request or would like to report a problem,
please email "sup...@barebones.com" rather than posting to the group.

--
You received this message because you are subscribed to the"TextWrangler Talk" discussion group on Google Groups.
To post to this group, send email to textwr...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/textwrangler?hl=en
If you have a feature request or would like to report a problem,please email "sup...@barebones.com" rather than posting to the group.

Reply all
Reply to author
Forward
0 new messages