postcss-replace icon indicating copy to clipboard operation
postcss-replace copied to clipboard

Pattern doesn't match with trailing whitespace

Open picobots opened this issue 1 year ago • 0 comments

Given the following CSS:

body {
  margin: 0;
}

If I include a trailing space at the end of my regular expression pattern, postcss-replace will not perform the replacement. For example, this postcss-replace config does not work (note the space character after the word "body") :

// This does not work
postcssReplace({
  pattern: /body /g,
  data: { replaceAll: "BLAH " }
}),

But if I remove the trailing space, then the replacement works correctly:

// This works correctly
postcssReplace({
  pattern: /body/g,
  data: { replaceAll: "BLAH" }
}),

Any idea what's happening here? According to this test on RegExr, a trailing space should correctly match in this scenario. I've tried using \s to match any whitespace character and that does not work either. Something odd seems to be going on with whitespace at the end of the regular expression pattern.

picobots avatar Oct 28 '23 15:10 picobots