# Extracting a float from a string

**URL:** <https://discourse.julialang.org/t/extracting-a-float-from-a-string/43126>\
**Category:** New to Julia\
**Tags:** strings, regex\
**Created:** [July 15, 2020, 12:45pm UTC](https://discourse.julialang.org/t/extracting-a-float-from-a-string/43126 "2020-07-15T12:45:01Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 15, 2020, 1:24pm UTC](https://discourse.julialang.org/t/extracting-a-float-from-a-string/43126/8 "2020-07-15T13:24:28Z")

</div>

> [@erlebach](#):
>
> What solutions does Julia offer besides regular expressions?

Any particular reason you want to avoid regexps? They are often a good solution for tasks like this.

To compare with @oheil’s nice solution,

```julia
using BenchmarkTools
strg="time t=0.234_ext.bson"
f1(str) = parse(Float64, split(split(str, '=')[2], '_')[1])
f2(str) = parse(Float64, match(r".*=(.*)_.*", str).captures[1])

julia> @btime f1($strg)
  592.303 ns (6 allocations: 448 bytes)
0.234

julia> @btime f2($strg)
  389.634 ns (4 allocations: 288 bytes)
0.234

```

In addition, it is easier to do more validation wiht regexps.

---

_[View the full topic](https://discourse.julialang.org/t/extracting-a-float-from-a-string/43126)._
