Skip to main content

Module regex_replace

Module regex_replace 

Source
Expand description

preg_replace($pattern, $replacement, $subject) support - the target of larust-convert’s Blade expression translator (larust_convert:: blade::expr::translate’s "preg_replace" arm). That translator only ever emits a call here after already compiling the same pattern literal with this exact regex crate at convert time (its own self-check, mirroring syn::parse_str::<syn::Expr>’s role everywhere else in that translator) - so replace_all’s pattern argument is never expected to fail to compile for converter-generated call sites. It still doesn’t panic on one that does (a hand-written call, or a pattern edited after conversion): falling back to returning subject unchanged is the same “never fail, best-effort” choice larust_support::date::strtotime already makes, for the same reason - this is a runtime helper, not the converter’s own convert-time rejection path.

Functions§

replace_all
Replaces every match of pattern (a Rust regex-syntax pattern - larust-convert is responsible for translating PHP’s PCRE delimiter/ flag syntax into this form before ever generating a call here) in subject with replacement, which may use $1-style backreferences exactly like PHP’s own preg_replace replacement string. replacement/subject accept both String and &str so the converter’s own translated sub-expressions (a string literal, or a format!(...)-produced String from a .-concatenation) both work as call-site arguments without the converter needing to know which shape it produced.