I need to find lines that contains more than 10 of "," (I have got errors importing CSV, so I need to correct it manually). I'm using Notepad++ so I not need to write reqex to match line, only to match comas.
(.*,.*){11,100} //does not work
The character + in a regular expression means "match the preceding character one or more times". For example A+ matches one or more of character A. The plus character, used in a regular expression, is called a Kleene plus .
Match any specific character in a setUse square brackets [] to match any characters in a set. Use \w to match any single alphanumeric character: 0-9 , a-z , A-Z , and _ (underscore). Use \d to match any single digit. Use \s to match any single whitespace character.
?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).
3. What is the Regular Expression Matching Zero or More Specific Characters? Explanation: Zero or Specific Expression matching can be done only by a single character that is*.
.*
also matches commas. You need to exclude those with a negated character class ([^,]
matches any character except commas):
^[^,\r\n]*(?:,[^,\r\n]*){11,}$
I've added \r\n
to the character class or it will match across newlines.
Be aware, though, that this will also count commas that are contained within quoted strings, so if you have those, you will misjudge the number of fields in your CSV row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With