bracketXtract <- function(txt, br = c("(", "[", "{", "all"), with=FALSE)  {
## SOURCE: @MartinMorgan : 
## http://stackoverflow.com/questions/8621066/remove-text-inside-brackets-parens-and-or-braces   
    br <- match.arg(br)
    left <-        # what pattern are we looking for on the left?
        if ("all" == br) "\\(|\\{|\\["
        else sprintf("\\%s", br)
    map <-         # what's the corresponding pattern on the right?
        c(`\\(`="\\)", `\\[`="\\]", `\\{`="\\}",
          `\\(|\\{|\\[`="\\)|\\}|\\]")
    fmt <-         # create the appropriate regular expression
        if (with) "(%s).*?(%s)"
        else "(?<=%s).*?(?=%s)"
    re <- sprintf(fmt, left, map[left])
    ret <- regmatches(txt, gregexpr(re, txt, perl=TRUE))    # do it!

    if (length(ret==1))
        return(ret[[1]])
    ret
}
