Perform a regular expression match, using PHP's preg_match or preg_match_all function, and return the matches.
- Service:
CleverAge\ProcessBundle\Transformer\String\PregMatchTransformer - Transformer code:
preg_match
Any value that can be cast to string, or null.
array: the$matchesarray filled bypreg_match/preg_match_all(an empty array when nothing matches withpreg_match)nullif the input isnullor an empty string
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
pattern |
string |
X | The regular expression, with delimiters | |
flags |
int |
0 |
PREG_* flags passed to the function (e.g. !php/const PREG_OFFSET_CAPTURE) |
|
offset |
int |
0 |
Offset (in bytes) from which to start the search | |
mode_all |
bool |
false |
If true, use preg_match_all instead of preg_match |
'foobarbaz'becomes['foobarbaz', 'foo', 'bar', 'baz']
# Transformer options level
preg_match:
pattern: '/(foo)(bar)(baz)/'- Capture offsets and keep only the 2nd group:
'foobarbaz'becomes['bar', 3]
# Transformer mapping level
second_group:
code: '[text]'
transformers:
preg_match:
pattern: '/(foo)(bar)(baz)/'
flags: !php/const PREG_OFFSET_CAPTURE
property_accessor:
property_path: '[2]'- Get all numbers of a string:
'a1b22c333'becomes[['1', '22', '333']]
# Transformer options level
preg_match:
pattern: '/\d+/'
mode_all: true