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

No 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 to match first set of curly braces:

process:
  extracted_value:
    plugin: preg_match
    source: source_field
    pattern: '/\{([^}]*)\}/'
    group_index: 1

Example to extract the url attribute value:

process:
  extracted_value:
    plugin: preg_match
    source: source_field
    pattern: '/url="([^"]+)"/'
    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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

baikho created an issue. See original summary.

baikho’s picture

Status: Active » Needs review
heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Could use tests and enhanced docs.

baikho’s picture

Issue summary: View changes
baikho’s picture

Issue summary: View changes
baikho’s picture

Status: Needs work » Needs review

  • heddn committed 71ed137d on 6.0.x authored by baikho
    feat: #3536607 Add preg_match process plugin to extract substrings using...
heddn’s picture

Status: Needs review » Fixed

Thanks for your contributions.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.