I’m trying to implement a hook script in Subversion, using findstr with a regular expression. The intent is to enforce the inclusion of an entry in the log message that matches the format used by our issue tracking tool (Atlassian JIRA). Our issues each consist of 4 to 6 capital letters and 2 to 4 numerals, separated by a hyphen (e.g., “TEST-554″ or CMMGT-392”). Per instructions in the Subversion documentation, I’ve created a batch file to check the log message for a correctly-formatted entry, using the regex
findstr ([A-Z]{3,6}\-[0-9]{2,4}) > nul
I’ve tested the regex in a number of testing tools and it seems to work, but when I run it as part of the hook script, it fails to return a match. As a sort of “control”, I tried using the regex
findstr ...... > nul
and was able to find a match. Anyone see where I’m going wrong?
findstrrequires the/Roption to use regular expressions, but it doesn’t support extended regular expressions, so things like counts ({3,6}) don’t work. Also, zero-or-one matches (?) don’t work, so doing what you want will get pretty verbose. Also, English Windows collation means that[A-Z]matches ‘A’, ‘b’, ‘B’, ‘z’, and ‘Z’, but not ‘a’. Here’s something that might work:This incredibly verbose command may exceed the maximum command length of the shell (haven’t checked), but basically does what you want by containing a separate match for each of the permutations of letter and number counts. That’s another odd thing about
findstr: unless you use the/Coption, spaces in your match string will be used to separate it into individual match expressions.If you have any option besides
findstrsuch as PowerShell, Python, or even VBScript, I would suggest you use it. Good luck!EDIT: Here’s the Perl one-liner I used to generate the above command: