Hi there, say I have this situation:
ul a[href$=".pdf"]{...}
to match any link that end in .pdf: how do I match any possible combination of "pdf"? Say "pDf", "PDF" etc?
I thought that I could use regex in the css, but I really don't know anything about regex, so I came up with this selector but I have no idea if it will work or not:
ul a[href$="/.pdf/i"]{..} because I am not sure whether I need to escape quotes or not
Or a more longwinded one could be the following rules in the css

ul a[href$=".pdf"]{...}
ul a[href$=".Pdf"]{…}
ul a[href$=".PDf"]{…}
ul a[href$=".PDF"]{…}
ul a[href$=".pDF"]{…}
ul a[href$=".pdF"]{…}
ul a[href$=".PdF"]{…}
ul a[href$=".pDf"]{…}

The possible combinations should 8 or 9? Not quite sure
Any help appreciated
thanks

Recommended Answers

All 6 Replies

ul a[href$=".pdf"]{...} should be the one you need. AFAIK it should be case insensitive (except for class and id attributes), but am not sure if this is correctly implemented across browsers.

afraid it's not inplemented correctly, and it seems to be case sensitive, I have tested it already. With that rule if you have something like "abc.Pdf" it doesn't work

I assume your handling uploads. Wouldn't the easier option be to ensure everything IS lowercase? If not, you'll need the list of eight rules you mentioned.

That's correct pritaeas in that users will upload the pdf through a cms when needed. As you correctly says, yes, it will be much easier to ensure everything is lower case, but because I effectively won't have control on what goes on the site (in that I can't force users to use lower case .pdf), I have to ensure that the code is as robust as possible and take into account human error, if we want to call it like that. This rule ul a[href$=".pdf"]{...} unfortunately isn't that robust, so I was hoping to find a good alternative (regex was the only one that come in mind without using any javascript of course) to replicating effectively the same rule 8 times
thanks

I effectively won't have control on what goes on the site

True, but if you wrote the upload code, adding a lower case conversion is relatively easy.

you mean like a script to convert it into lower case?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.