regex for word in parentheses ?

  • Follow


Hi,

I need a regex in tcl to get the word that's inside a pair of
parentheses (excluding the parentheses themselves). For example, my
string is "hello there (WORD) stuff" and I need to get the WORD inside
the parentheses (without the actual parentheses. There's only one pair
of parentheses in my strings. I have tcl 8.5 on Windows.

Can you help me? Thank you,

Thibaud
0
Reply Thibaud 10/31/2010 9:36:10 AM

Thibaud wrote:
> Hi,
> 
> I need a regex in tcl to get the word that's inside a pair of
> parentheses (excluding the parentheses themselves). For example, my
> string is "hello there (WORD) stuff" and I need to get the WORD inside
> the parentheses (without the actual parentheses. There's only one pair
> of parentheses in my strings. I have tcl 8.5 on Windows.
> 
> Can you help me? Thank you,
> 
> Thibaud

% set string {string is "hello there (WORD) stuff" and I need to get the WORD inside}
string is "hello there (WORD) stuff" and I need to get the WORD inside
% regexp {.*\((.*?)\).*}  $string  dummy parenta
1
% set dummy
string is "hello there (WORD) stuff" and I need to get the WORD inside
% set parenta
WORD
%

% regexp {\((.*?)\)}  $string  dummy parenta
1
% set dummy
(WORD)
% set parenta
WORD
%

the nongreedy qualifier '?' keeps the re gobling up multiple
(.*) occurences into one single match.

uwe
1
Reply Uwe 10/31/2010 10:40:35 AM


It works! I had the correct regex (same as your second one) but I was
reading off the first parameter after my string, and I didn't know
about the second parameter (which is the one I need). Thanks!!
0
Reply Thibaud 11/1/2010 5:12:31 AM

2 Replies
1138 Views

(page loaded in 0.149 seconds)

Similiar Articles:













7/19/2012 5:53:31 PM


Reply: