I am new to regular expressions. I have been reading about regex for last couple of hours to understand how to use regex* to achieve the following, but with not much luck. My brain has started hurting. Hence this call for help. Following are the restrictions I want to apply to a data input field, what regular expression should I use?
- The first and last character should be either alphanumeric, "." (i.e. dot) or "_" (i.e. underscore)
- The characters between the first and last charatcers can be alphanumeric, "." (i.e. dot), "_" (i.e. underscore) or "-" (i.e. hyphen)
- Characters "." (i.e. dot) and "-" (i.e. hyphen) cannot appear consecutively.
- There should be atleast one alphanumeric character in the input.
Some valid input data:
.abc_
__abc.d-e.
.__a.
.a__b.
_a-b.
abc
a___.
Thanks and regards,
~Plug
- I am using a third-party library that internally uses boost-regex to parse the expression.