PowerShell Regex for repeating character -


i have csv-file contains empty lines want filter out of result. when know input, know how many commas expect , filter them out this:

"test 1, text a,", "test 2, text b,", ",," | {$_ -ne ",," } 

how regex filter out empty lines regardless of how many commas there are? because never know upfront how many columns there be.

in following example able retrieve same result in previous example:

"test 1, text a,", "test 2, text b,", ",,", ",", ",,," | {$_ -ne ",," } 

thank help.

you can try following code:

"test 1, text a,", "test 2, text b,", ",,", ",", ",,,"           | {!([regex]"^[,]+$").match($_).success} 

which search lines has more 1 comma between begin (char ^) , end of string (char $)

you can simplify expression below one:

"test 1, text a,", "test 2, text b,", ",,", ",", ",,," | {$_ -notmatch "^[,]+$"} 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -