none
How to extract all the colume name quoted by [ and ]? RRS feed

  • Question

  • suppose I have a dynamic sql as

    "select col1,col2, [col name1], col3,col4,[col name2],col5,[col name3] ..."

    And I need to extract all the col name* which are quoted by [ and ], but I don't know how many they are. How to use regular expression to do that?

    Thursday, September 15, 2011 2:34 AM

Answers

  • This should work
    $s = "select col1,col2, [col name1], col3,col4,[col name2],col5,[col name3]"
    $r = "\[.*?\]"
    $return = $a | select-string $r -AllMatches
    $return.matches
    

    • Marked as answer by Daniel Wu Thursday, September 15, 2011 4:23 AM
    Thursday, September 15, 2011 3:19 AM