There are times when separators within source data are more complex than a comma or set of characters and regular expression patterns could greatly help.
I think there are plenty of use-cases for this functionality and the implementing it is incredibly simple. I recently had to do an import of exported MS Exchange data which had some pretty messy and unpredictable separators and this patch helped a lot. With Regular expressions it's also possible to use multiple delimiters so if you have messy input data which has comma separators as well as period separators you could easily process that data.
Performance issues
Explode needs to be kept as the default splitting function because it's meant to be significantly faster than preg_split. In this patch, regular expressions are off by default.
Attached is a patch that allows developers to use regular expressions in separators using the following syntax within their migration class.
$this->addFieldMapping('field_name', 'ColumnName')
->separator('/SomeRegexPattern/', $useRegex = TRUE);
| Comment | File | Size | Author |
|---|---|---|---|
| migrate_allow_regex_separators.patch | 2.12 KB | codesidekick |
Comments
Comment #1
codesidekick commentedChanged to needs review.
Comment #2
mikeryanSorry, I think this is just too narrow a use-case to be worth incorporating into the base Migrate module, particularly since it's so easily accomplished with existing functionality:
Comment #3
codesidekick commentedGreat, I didn't realise you could do callbacks (didn't come across any documentation on that). Hopefully this post helps make people aware of them when they're trying to do more complex separators.