Re: removing parenthesis
Re: removing parenthesis
- Subject: Re: removing parenthesis
- From: Thomas Fischer <email@hidden>
- Date: Thu, 29 Mar 2012 01:25:40 +0200
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
>
>
> On 7 Jun. 2011, 10:43, Thomas Fischer <email@hidden> wrote:
>> 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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden