I think you could use negative look-behind for this scenario since the commas that are not of interest to you seem to be preceeded by a number:
$str = @'
CREATE table test ( DISTRICT VARCHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC,
CUSTOMER_ACCOUNT DECIMAL(8,0),
CUSTOMER_SUB_ACCOUNT DECIMAL(3,0),
SERVICE_SEQ_NUM DECIMAL(7,0),
EFFECTIVE_DATE TIMESTAMP(0),
SUBSCRIBER_SEQ_NUM DECIMAL(7,0) )
'@
$str -split '(?<!\d),'
CREATE table test ( DISTRICT VARCHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC
CUSTOMER_ACCOUNT DECIMAL(8,0)
CUSTOMER_SUB_ACCOUNT DECIMAL(3,0)
SERVICE_SEQ_NUM DECIMAL(7,0)
EFFECTIVE_DATE TIMESTAMP(0)
SUBSCRIBER_SEQ_NUM DECIMAL(7,0) )
Note this is using PowerShell 2.0's -split
operator.
For paren matching, you might try something like this:
$re = [regex]@'
(?x)
\(
(?>
[^()]+
|
\( (?<DEPTH>)
|
\) (?<-DEPTH>)
)*
(?(DEPTH)(?!))
\)
'@
if ($str -match $re) {
$matches[0]
}
Outputs:
(
DISTRICT VARCHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC,
CUSTOMER_ACCOUNT DECIMAL(8,0),
CUSTOMER_SUB_ACCOUNT DECIMAL(3,0),
SERVICE_SEQ_NUM DECIMAL(7,0),
EFFECTIVE_DATE TIMESTAMP(0),
SUBSCRIBER_SEQ_NUM DECIMAL(7,0)
)
See this blog post for more help on paren matching.