Add preg_match process plugin to extract substrings using regex

Created on 17 July 2025, 17 days ago

Problem/Motivation

Adding a preg_match plugin for extracting substrings using regular expressions.

This is a common need during migrations; for example, extracting values enclosed in characters or matching a known pattern. Without a preg_match plugin, users must write custom callbacks or process plugins for a simple operation.

Steps to reproduce

1. Attempt to extract part of a source value using regex.
2. Use str_replace with regex: true, but realize it only replaces content.
3. No preg_match plugin exists to extract matching values.

Proposed resolution

Add a preg_match process plugin that uses preg_match() to extract matched content.

Configuration options:

  • pattern: the regex pattern
  • group_index: which capture group to return (default: 0)

Example usage:

process:
  extracted_value:
    plugin: preg_match
    source: source_field
    pattern: '/some-pattern/'
    group_index: 1

Remaining tasks

  • Add plugin under Plugin/migrate/process/PregMatch.php
  • Add test coverage
  • Document usage

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Feature request
Status

Active

Version

6.0

Component

Plugins

Created by

🇧🇪Belgium baikho Antwerp, BE

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024