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.

Yunde




On Thu, Nov 12, 2015 at 8:24 AM JobJob <[email protected]> wrote:

> Forgot to say: welcome to Julia :)
>
> btw you can see the different methods for a function with e.g.:
> julia> methods(replace)
>
> also to see available documentation for a function type ?, e.g.
> ?replace
>
>
>

Reply via email to