The sample you want is similar to ( see it on rubular.com ):
^[a-zA-Z0-9_.-]*$
Explanation:
^ is the beginning of the string binding$ is the end of the string binding[...] is a character class definition* - repetition of "zero or more"
Please note that the literal dash is the last character in the definition of the character class, otherwise it has a different meaning (i.e. range). . also has different meanings outside the definition of character classes, but inside it is just literal .
References
In php
Here is a snippet to show how you can use this template:
<?php $arr = array( 'screen123.css', 'screen-new-file.css', 'screen_new.js', 'screen new file.css' ); foreach ($arr as $s) { if (preg_match('/^[\w.-]*$/', $s)) { print "$s is a match\n"; } else { print "$s is NO match!!!\n"; }; } ?>
The above prints ( as seen on ideone.com ):
screen123.css is a match screen-new-file.css is a match screen_new.js is a match screen new file.css is NO match!!!
Note that the pattern is slightly different using \w . This is the character class for the "word character".
API Links
Specification Note
This seems to fit your specification, but note that it will fit things like ..... etc. that may or may not be what you want. If you can be more specific which pattern you want to match, the regex will be a little more complicated.
The above regex also matches an empty string. If you need at least one character, use + (one or more) instead of * (zero or more) to repeat.
In any case, you can clarify your specification (it always helps when asking a question about regular expression), but I hope you can also learn how to write a template yourself, given the above information.
polygenelubricants Jun 12 2018-10-12 12:25
source share