W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2006

[whatwg] Web Forms: pattern attribute

From: Dean Edwards <dean@edwards.name>
Date: Sat, 22 Apr 2006 19:51:49 +0100
Message-ID: <444A7B45.1050504@edwards.name>
Michel Fortin wrote:
> Le 3 avr. 2006 ? 19:33, Dean Edwards a ?crit :
> 
>> Michel Fortin wrote:
>>
>>> Does that mean that a pattern attribute like "foo|bar" should 
>>> translate to /^foo|bar$/ ? Wouldn't it make more sense it it was 
>>> /^(foo|bar)$/ with the parentesis?
>>
>> You have a point. Would implied parentheses cause any side effects? 
>> None that I can think of...
> 
> Now that you mention it, it could. With a pattern like this:
> 
>     "(.).*\1"
> 
> which simply indicates that the first and the last characters must be 
> the same, reference numbers won't refer to the right part. When the 
> pattern get transformed to this:
> 
>     /^((.).*\1)$/
> 
> it makes `\1` a reference to the whole input text (the first 
> parenthesis) rather than the first character (which has become the 
> second parenthesis). This is not good.
> 
> So we will need to use a non-matching group `(?: ... )` instead:
> 
>     /^(?:(.).*\1)$/
> 
> Problem solved.
> 

Very neat. However, I think it would be best if the UA did this little 
trick itself. :-)

-dean
Received on Saturday, 22 April 2006 11:51:49 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:46 UTC