I have a string that I would like to validate a certain pattern for: Here’s the string:
[alphanumeric characters at the start of the line, then->] ?,?,?,?,?[lines end with: vb|cr|crlf]
What I’d like to achieve as a validation would be to ensure the following, pertaining to the “?,?,?,?,?” string:
-
Validation should return false if there are more than one question mark (?) or comma (,) together. An example that should cause failure would be:
?? <or> ,, <or> ??? <or> ,,, -
Validation at the end of the line should just be for question marks (?) and commas (,). No other characters…
-
The last value in the string in question (which, again, is:
"?,?,?,?,?") should always be a question mark and not a comma. -
Similarly, the start of this string should always be a question mark and not a comma.
I’m hoping that this would be possible with the preg_match function, but please let me know if it isn’t possible.
How about this regex? It matches your test case.
Now, the regex matches:
Read )Aloud Your Alphabet(?,?,?vb|cr|crlfRead )In Silence Respect(vb|cr|crlfDemo (This demo omits the above added question mark)