Fork me on GitHub
#meander
<
2021-04-23
>
wilkerlucio04:04:46

hello, I’m trying to understand how to use m/re to match something, but I always get nil, example:

(m/find "csa sa R$ 231,52 casa"
    (m/re #"\d{3},\d{2}" ?0)
    ?0)
is this intended to be used to match like this?

Jimmy Miller12:04:42

On my phone. But from the doc string re uses re-matches. Which matches the whole string. So my guess is you need a pattern that matches the entire string, not just part of it.

wilkerlucio13:04:55

humm, is there a way to use with re-find? in my case I have these long strings, and just wanna match a small portion of it, and extract it in the process

wilkerlucio13:04:36

I’m getting around using (m/pred #(re-find ...)), but that forces me to run the regex twice (to extract the content later), and look ugly, the syntax on m/re is just perfect, but having problems to match the small string in a long text

Jimmy Miller13:04:56

Would changing you regex to this and grabbing group 1 not work? .**(\d{3},\d{2}).**

Jimmy Miller13:04:22

Or are you looking for multiple matches?

Jimmy Miller13:04:42

If so, I can look at this later when not on my phone.

wilkerlucio13:04:12

no, a single match, I got it work with #"(?s).*(\d+,\d{2}).*" 🙂

wilkerlucio13:04:19

humm, kind of

wilkerlucio13:04:35

it matches, but now it matches the last occurence, while I need the first

wilkerlucio13:04:41

I guess having one to match all would be nice

Jimmy Miller13:04:29

Just change the first to non-greedy star .*?

wilkerlucio13:04:28

sorry, was my bad, its matching the right thing 🙂

wilkerlucio13:04:35

and yes, non-greedy should solve if that was the case

wilkerlucio13:04:43

all working nice now, thanks @U5K8NTHEZ!

Jimmy Miller13:04:59

No problem :). Glad it is working.