I am trying to make an <input> field that uses a pattern to check if the input is a valid windows file path.
The pattern I have is
/^(?:[\w]\:|\\)(\\[a-zA-Z_\-\s0-9\.()~!@#$%^&=+';,{}\[\]]+)+\.(exe)$/g
However, when putting this into the pattern attribute of an <input> field:
<input id="path" type="text" pattern="^(?:[\w]\:|\)(\[a-zA-Z_\-\s0-9\.()~!@#$%^&=+';,{}[]]+)+\.(exe)$">
An error is displayed in the console saying:
Pattern attribute value
^(?:[\w]\:|\\)(\\[a-zA-Z_\-\s0-9\.()~!@#$%^&=+';,{}\[\]]+)+\.(exe)$ is
not a valid regular expression: Uncaught SyntaxError: Invalid regular
expression: /^(?:[\w]\:|\\)(\\[a-zA-Z_\-\s0-9\.()~!@#$%^&=+';,{}\[\]]+)+\.(exe)$/:
Invalid escape
I have tried several ways of writing this pattern, but none seem to work.
patternattribute already matches the whole string, so^and$are not needed. It's worth also noting that file paths can use/instead of \.