Posted to tcl by kbk at Sat Jan 21 17:27:32 GMT 2012view pretty

% regexp -expanded {
    (?:^|[ ])      # this matches either the start of the string, or else
                   # a single space character
    test           # this matches the desired word, 'test'
    (?:$|[ ])      # this matches either the end of string, or else a
                   # single space character
} test
1
% regexp -expanded {
    (?:^|[ ])      # this matches either the start of the string, or else
                   # a single space character
    test           # this matches the desired word, 'test'
    (?:$|[ ])      # this matches either the end of string, or else a
                   # single space character
} {this is a test case} 
1
% regexp -expanded {
    (?:^|[ ])      # this matches either the start of the string, or else
                   # a single space character
    test           # this matches the desired word, 'test'
    (?:$|[ ])      # this matches either the end of string, or else a
                   # single space character
} {I protest!}
0