Search code examples
regexcsvfindstr

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)?)$

Solution

  • 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.