开发者

using findstr with regex to search through CSV

I was wondering if it's possible to use findstr开发者_如何学运维 to search through a CSV for anything matching this regular expression

^([BPXT][0-9]{6})|([a-zA-Z][a-zA-z][0-9][0-9](adm)?)$


I don't know which language you're talking about, but there is one obvious problem with your regex: The ^ and $ anchors require that it matches the entire string, and you seem to be planning on matching individual entries in your CSV file.

Therefore, you should use word boundary anchors instead if your regex engine supports them:

\b(?:([BPXT][0-9]{6})|([a-zA-Z]{2}[0-9]{2}(adm)?))\b

I've also added another non-capturing group around the alternation. In your regex the anchors at the start and end of the string would have been part of the alternation, which is probably not intended. Whether you really need all the other parentheses depends on what you're going to do with the match.


No, it is not possible to use findstr to search for matching substrings, especially those matching the complex expression you've provided.

findstr is a Windows built-in.

findstr /? shows the subset of regex that it can use:

Regular expression quick reference:
  .        Wildcard: any character
  *        Repeat: zero or more occurrences of previous character or class
  ^        Line position: beginning of line
  $        Line position: end of line
  [class]  Character class: any one character in set
  [^class] Inverse class: any one character not in set
  [x-y]    Range: any characters within the specified range
  \x       Escape: literal use of metacharacter x
  \<xyz    Word position: beginning of word
  xyz\>    Word position: end of word

This means that most of your expression is out the window.

Also, findstr can't limit its output to just the matched expression; it only identifies lines containing matches.

It is entirely unsuitable for the task described.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜