0

I'm having one heck of a time figuring out regular expression in the context of the grunt-string-replace plugin.

I'm basically trying to take something like this:

!random-cssmixin{}

And turn it into this:

.random-cssmixin;

Is it possible to do this or does regular expression simply allow to you manipulate the text between?

My Gruntfile.js:

'string-replace': {
          dist: {
              expand: true,
              flatten: true,
              src: devRoot + ['/css/*.less'],
              dest: sqsRootCss,
          options: {
              replacements: [{
                   pattern: /\$/g,
                   replacement: "@"
              }, {
                  pattern: "No clue",
                  replacement: "No idea"

              }]
            }
          },
      },
jasonbarone
  • 172
  • 3
  • 17
  • what is your sample input and expected output? – Federico Piazza Apr 12 '15 at 23:38
  • I put the example at the top of the question. I'm writing LESS CSS using the format !random-class{} and the expected output should be .random-class; – jasonbarone Apr 12 '15 at 23:40
  • The reason I'm going through this is because I'm using some grunt plugins, one of which is autoprefixing. I'm writing CSS in LESS syntax, but I do NOT want the CSS compiled because my website CMS SaaS platform does this for me. So my output needs to be in uncompiled LESS. The problem is the Autoprefix doesn't understands LESS, so it breaks. To get around this I'm creating my own syntax using supported characters like the example above. – jasonbarone Apr 12 '15 at 23:42

1 Answers1

1

You can use a regex like this:

!([\w-]+)\{\}

Working demo

And then use the replacement string:

.\1;

Check the substitution section to see your expected output

enter image description here

Federico Piazza
  • 30,085
  • 15
  • 87
  • 123