正则表达式是否允许您替换单词的结尾和开头?

Does regular expression allow you to replace the ending and beginning of a word?

我有一段时间在 grunt-string-replace 插件的上下文中找出正则表达式。

我基本上是在尝试这样的事情:

!random-cssmixin{}

然后把它变成这样:

.random-cssmixin;

是否可以这样做,或者正则表达式是否仅允许您操作之间的文本?

我的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"

              }]
            }
          },
      },

您可以像这样使用正则表达式:

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

Working demo

然后使用替换字符串:

.;

检查 substitution section 以查看您的预期输出