Yes, it is what I was looking for. It allows me to pass in local variables.
Thanks, JobJob.
One more questions. This replace function allows access to each match in a SubString format. Is there any function to allow the access to each match in the format of RegexMatch to exposure the "captures"?
For example: I'd like to convert time format to remove "am" and "pm". Below is one solution (to parse time string twice):
y = "time format 02:45pm, 14:20, 03:45am"
f(x) = replace(x, r"^0\d:[0-6]\d(am|pm)"i, x->lowercase(x[end-1])=='a'?x[1:end-2]:string(parse(Int,x[1:2])+12, x[3:end-2]));
replace(y, r"([01]\d)(:[0-6]\d)(am|pm)"i, f)
# "time format 14:45, 14:20, 03:45"
If the replace function allows to access each match in RegxMatch format, then the solution could be something like this:
replace(y, r"([01]\d)(:[0-6]\d)(am|pm)"i, x->x.capture[3]=="am"?x[1:end-2]:string(parse(Int, x.captures[1])+12, x.captures[2]))
and it only needs to parse the time string once.
Thanks, again. Julia is great.