phpaliuk Posted July 8, 2020 Share Posted July 8, 2020 (edited) Hi - for a CSS minifier I have, how do I find strings that match a pattern of: }.[anytext].[anytext]{ and put a whitespace inbetween the fullstops, eg:- }.class1.class2{ --> becomes --> }class1. class2{ }.name1.myname2.anothername3{ --> becomes --> }name1. myname2. anothername3{ Many thanks for your help, Alex Edited July 8, 2020 by Barand add code tags Quote Link to comment Share on other sites More sharing options...
requinix Posted July 8, 2020 Share Posted July 8, 2020 You do know that ".class1.class2" and ".class1 .class2" mean two different things, right? Is the minifier buggy and incorrectly removing the space? Or is the source it's processing incorrect? How about more of a description about what's going on, why you have this problem in the first place, and exactly what you need when you say "find strings that match a pattern of"? Quote Link to comment Share on other sites More sharing options...
maxxd Posted July 9, 2020 Share Posted July 9, 2020 What minifier are you using? As requinix pointed out, `.class1.class2` is very different from `.class1 .class2` and if your minifier is adding or removing spaces like that it's broken. I always had good luck with cssmin if you're using gulp - I assume it's usable via webpack. Quote Link to comment Share on other sites More sharing options...
phpaliuk Posted July 9, 2020 Author Share Posted July 9, 2020 (edited) I wrote the CSS minifier myself. It removes whitespace and newlines and comments, but because I don't know how to code a pattern matching for multiple classnames as posted, it removes whitespace from between the class names as well. As mentioned, 'class1.class2' is different to '.class1 .class2'. Is there a way to pattern match text between braces }xxx{ and replace .class1.class2...etc... with the space? Edited July 9, 2020 by phpaliuk Quote Link to comment Share on other sites More sharing options...
requinix Posted July 9, 2020 Share Posted July 9, 2020 Given that you wrote the minifier yourself, it's going to be very hard for us to recommend anything given we have absolutely no idea what the minifier is or how it works. I mean, I can't even tell if it's written in PHP... And on that note, why did you write it yourself? There are plenty of existing minifiers out there that don't have bugs like stripping significant whitespace. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.