Repository: prettier/prettier
File: src/language-css/print/misc.js (JavaScript)

Code before:
}

const STRING_REGEX = /(["'])(?:(?!\1)[^\\]|\\.)*\1/gsu;
const NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:e[+-]?\d+)?/giu;
const STANDARD_UNIT_REGEX = /[a-z]+/giu;
const WORD_PART_REGEX = /[$@]?[_a-z\u0080-\uFFFF][\w\u0080-\uFFFF-]*/giu;
const ADJUST_NUMBERS_REGEX = new RegExp(
  STRING_REGEX.source +
    "|" +
    // eslint-disable-next-line regexp/no-misleading-capturing-group
    `(${WORD_PART_REGEX.source})?` +
    `(${NUMBER_REGEX.source})` +
    `(${STANDARD_UNIT_REGEX.source})?`,
  "giu",
);

function adjustStrings(value, options) {
  return value.replaceAll(STRING_REGEX, (match) => printString(match, options));
}

function quoteAttributeValue(value, options) {
  const quote = options.singleQuote ? "'" : '"';

  // Check if the value ends with `s`, `S` or `I`, `i` can be solved by postcss
  let flag = "";
  const match = value.match(/^(?<value>.+?)\s+(?<flag>[sSI])$/u);
  if (match) {
    ({ value, flag } = match.groups);
  }

  return (
    (value.includes('"') || value.includes("'")
      ? value
      : quote + value + quote) + (flag ? ` ${flag}` : "")
  );
}

function adjustNumbers(value) {
  return value.replaceAll(
    ADJUST_NUMBERS_REGEX,
    (match, quote, wordPart, number, unit) => {
      if (!wordPart && number) {
        unit ??= "";
        unit = unit.toLowerCase();

        if (
          !unit ||
          // `2n + 1`
          unit === "n" ||
          CSS_UNITS.has(unit)
        ) {

Review comment (bug):
I just tesed, `[foo=a b]` seems invalid in chrome.

```
$$('[x=a b]')
VM891:1 Uncaught SyntaxError: Failed to execute '$$' on 'CommandLineAPI': '[x=a b]' is not a valid selector.
    at <anonymous>:1:1
```

How about we treat all unknown letters as flag, so we don't need do anything if future flags are introduced.

Which will change the output of `[type=a   x]` added in #17841

Code after:
}

const STRING_REGEX = /(["'])(?:(?!\1)[^\\]|\\.)*\1/gsu;
const NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:e[+-]?\d+)?/giu;
const STANDARD_UNIT_REGEX = /[a-z]+/giu;
const WORD_PART_REGEX = /[$@]?[_a-z\u0080-\uFFFF][\w\u0080-\uFFFF-]*/giu;
const ADJUST_NUMBERS_REGEX = new RegExp(
  STRING_REGEX.source +
    "|" +
    // eslint-disable-next-line regexp/no-misleading-capturing-group
    `(${WORD_PART_REGEX.source})?` +
    `(${NUMBER_REGEX.source})` +
    `(${STANDARD_UNIT_REGEX.source})?`,
  "giu",
);

function adjustStrings(value, options) {
  return value.replaceAll(STRING_REGEX, (match) => printString(match, options));
}

function quoteAttributeValue(value, options) {
  const quote = options.singleQuote ? "'" : '"';

  // The selector parser currently only understand `i` flag,
  // but not `s`, `S`, and `I`
  // To support future flags, we simply check if it's an alphabet letter
  // https://github.com/prettier/prettier/pull/17865#discussion_r2332698101
  let flag = "";
  const match = value.match(/^(?<value>.+?)\s+(?<flag>[a-zA-Z])$/u);
  if (match) {
    ({ value, flag } = match.groups);
  }

  return (
    (value.includes('"') || value.includes("'")
      ? value
      : quote + value + quote) + (flag ? ` ${flag}` : "")
  );
}

function adjustNumbers(value) {
  return value.replaceAll(
    ADJUST_NUMBERS_REGEX,
    (match, quote, wordPart, number, unit) => {
      if (!wordPart && number) {
        unit ??= "";
        unit = unit.toLowerCase();

        if (
          !unit ||
          // `2n + 1`