Issue Bug Closed

#106512CKEditor 5: custom transformation do not allow null in regular expression transformation

Rémi Payette 04/04/25, 20:44 updated 04/14/26, 19:11

Description

I was trying to do the exact same thing as the original poster of #104827

The fix for the From: part works great, but null still isn’t accepted in the To: part, which for ckeditor means : dont replace that part, keep it as is.

https://ckeditor.com/docs/ckeditor5/latest/api/module_typing_typingconfig-TextTransformationDescription.html

Let say I want to put pipes around every word :

editor:
  config:
    typing:
      transformations:
        extra: [
          {
            from: { pattern: '(\s)([A-Za-z]*)(\s)$' },
            to: [ ' |', null, '| ' ]
          }
        ]
TypeError: right-hand side of 'in' should be an object, got null

I’m sorry if I missed something obvious, I have not yet earned my “typo3 master” badge.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 6

  1. S P commented <span data-processor="relativetime" data-value="2025-04-05T10:14:39+00:00" > 04/05/25, 10:14 </span>

    In your specific example it should be possible to just not capture the middle part:

    {
      from: { pattern: '(\s)[A-Za-z]*(\s)$' },
      to: [ ' |', '| ' ]
    }

    That’s generally true for regular expressions, by the way: only ever capture stuff you actually need. It performs faster, keeps code more readible and intentions more clear.

    If you need the parenthesis for scoping of complex expressions (disjunctions or similar), you can still mark them as non-captured using the ?: flag: (?:[A-Za-z]*) (I’m assuming a “normal” regex engine inside CKeditor – since it is JS it should be possible)

  2. Rémi Payette commented <span data-processor="relativetime" data-value="2025-04-07T15:07:37+00:00" > 04/07/25, 15:07 </span>

    I have not tested if it works ( the non-capture of certain groups ) but it’s contrary to what the ckeditor doc says :

    The input value (from) can be passed either as a string or as a regular expression.
    • If a string is passed, it will be simply checked if the end of the input matches it.
    • If a regular expression is passed, its entire length must be covered with capturing groups (e.g. /(foo)(bar)$/). Also, since it is compared against the end of the input, it has to end with $ to be correctly matched. See examples below.

    https://ckeditor.com/docs/ckeditor5/latest/api/module_typing_typingconfig-TextTransformationDescription.html ( 4th line of text in the page )

    I’m afraid it will work only in certain conditions or stop working at any update in the future.

  3. Rémi Payette commented <span data-processor="relativetime" data-value="2025-04-07T15:35:31+00:00" > 04/07/25, 15:35 </span>

    I tested without capturing group and with ?: , result are the same : the pipes get at the beggining of the replacement, space, and the word missing it’s first letter.

    someword

    become

    || omeword
  4. Garvin Hicking commented and changed status New Closed <span data-processor="relativetime" data-value="2026-04-14T19:11:43+00:00" > 04/14/26, 19:11 </span>

    I think this might have been fixed with #108800 – closing this, otherwise please feel free to reopen