A question I posted an answer to was deleted: Why does a regex using an unescaped dash -
character not seem to work in a pattern
attribute in HTML but it works when testing on regex101? (Screenshot of question and my answer).
The deleted question is also closed as a duplicate of Why is my regex valid with the RegExp u flag, but not with the v flag and does not work in HTML pattern attribute? however, in my opinion, it only partially overlaps. My answer does not apply directly to the duplicate.
What the question is about (background information):
The core of the issue is that there is a new flag for regular expressions introduced in JavaScript - previously there was a u
flag for handling Unicode characters and recently a v
flag was introduced which allows for far more flexibility in writing the regular expressions. That is what the duplicate target is about.
While v
has basically the same capabilities of u
but it also has extra features it is almost a straight upgrade. It does come with slightly stricter syntax that means that some older patterns would be invalid. What I think is going to be common is a character class that includes a dash, for example [ab-]
- it is common and idiomatic usage to put the dash at the either end of the character class to make sure it is interpreted as a dash and not a range. Otherwise it would need to be escaped, e.g., [a\-b]
. However, with the v
flag a dash always needs escaping, so a correct pattern is [ab\-]
Why I think the HTML part is distinct and worth preserving
However, the closed and now deleted question was asking about the HTML pattern
attribute which takes a regular expression and validates user input against it. The HTML specification was changed rather recently in April 2023 to now mandate that values of pattern
be used with the v
flag. Thus one could run into the u
vs v
discrepancy separate from the JavaScript change entirely.
This is indeed how I came across it - while researching for my answer. As a result, I also had to return to an older work application and make sure it still works since it uses HTML validation but it is configurable. I had to make sure that it would not throw errors for configurations that previously worked and has to keep on working.
This, I feel, is information absolutely worth preserving - the fact that the HTML specification has been changed and when as it would be useful for others that might be in my situation.
There are more ways this can be encountered, not only with old (pre-April 2023) applications but also older (pre-April 2023) tutorials, references, lectures, documentation that might use a now-invalid pattern.
That was the case with the now deleted question - the asker took the code from a textbook which was valid for when it was published.
While the differences between the u
and v
flags are absolutely relevant, I do not think the JavaScript answer to that is directly applicable to HTML questions. It is a component of the answer, not the whole thing.
This is why I believe the deleted information is relevant and belongs to be included in a library of useful programming topics.
Can it be preserved and how?
- Undeleting the question?
- Posting a new Q&A that focuses more on the HTML side of thing?
- Something else entirely?
Or just do nothing?
v
flag. I have to confess, I didn't notice that the question and answer were changed when I started writing the meta post.