Skip to content

Pattern doesn't match with trailing whitespace #309

@picobots

Description

@picobots

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions