| 1 |
(** [replace ~all re ~f s] iterates on [s], and replaces every occurrence |
| 2 |
of [re] with [f substring] where [substring] is the current match. |
| 3 |
If [all = false], then only the first occurrence of [re] is replaced. *) |
| 4 |
val replace |
| 5 |
: ?pos:int (** Default: 0 *) |
| 6 |
-> ?len:int |
| 7 |
-> ?all:bool (** Default: true. Otherwise only replace first occurrence *) |
| 8 |
-> Compile.re (** matched groups *) |
| 9 |
-> f:(Group.t -> string) (** how to replace *) |
| 10 |
-> string (** string to replace in *) |
| 11 |
-> string |
| 12 |
|
| 13 |
(** [replace_string ~all re ~by s] iterates on [s], and replaces every |
| 14 |
occurrence of [re] with [by]. If [all = false], then only the first |
| 15 |
occurrence of [re] is replaced. |
| 16 |
|
| 17 |
{5 Examples:} |
| 18 |
{[ |
| 19 |
# let regex = Re.compile (Re.char ',');; |
| 20 |
val regex : re = <abstr> |
| 21 |
|
| 22 |
# Re.replace_string regex ~by:";" "[1,2,3,4,5,6,7]";; |
| 23 |
- : string = "[1;2;3;4;5;6;7]" |
| 24 |
|
| 25 |
# Re.replace_string regex ~all:false ~by:";" "[1,2,3,4,5,6,7]";; |
| 26 |
- : string = "[1;2,3,4,5,6,7]" |
| 27 |
]} *) |
| 28 |
val replace_string |
| 29 |
: ?pos:int (** Default: 0 *) |
| 30 |
-> ?len:int |
| 31 |
-> ?all:bool (** Default: true. Otherwise only replace first occurrence *) |
| 32 |
-> Compile.re (** matched groups *) |
| 33 |
-> by:string (** replacement string *) |
| 34 |
-> string (** string to replace in *) |
| 35 |
-> string |