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
Issue fork migrate_plus-3536607
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
Comment #3
baikho commentedComment #4
heddnCould use tests and enhanced docs.
Comment #5
baikho commentedComment #6
baikho commentedComment #7
baikho commentedComment #9
heddnThanks for your contributions.