Replacing a string
Using pattern()->replace()
you can:
- Limit replacements with:
replace()->first()
replace()->all()
replace()->only(int)
- replace with a constant value -
with()
/withReferences()
- replace with a computed value -
callback()
- handle subjects that don't match the pattern for replacements -
otherwise()
/throwingOtherwise()
/returningOtherwise()
#
Limiting replacementsAfter replace()
, you need to explicitly use one of first()
/all()
/only(int)
methods, to express how many
replacements should be done.
Read on to learn more about replacing with a constant value.