gobo-eiffel / gobo

The Gobo Eiffel Project provides the Eiffel community with free and portable Eiffel tools and libraries.
https://sourceforge.net/projects/gobo-eiffel/
Other
59 stars 24 forks source link

Mac regex #39

Closed phgachoud closed 5 years ago

phgachoud commented 5 years ago

Any idea why the following regex with

needle: ^[0-9]{8}_([:alnum:]{2}[-:][:alnum:]{2}[-:][:alnum:]{2}[-:][:alnum:]{2}[-:][:alnum:]{2}[-:][:alnum:]{2})_.*

haystack: 20190818_30-45-11-B4-EF-5D_192.168.0.96_inverter_data.py.csv.bz2

code: `

                        l_reg: RX_PCRE_REGULAR_EXPRESSION

            create l_reg.make
            l_reg.compile (needle)
            check l_reg.is_compiled then
                l_reg.match (haystack)
                check l_reg.match_count >= 1 then
                    Result := l_reg.captured_substring (1)
                end
            end

`

doesn't give a match_count -> captured_string(1) for the mac address??

ebezault commented 5 years ago

I didn't try to run your code yet, but I have two remarks/questions:

phgachoud commented 5 years ago

I didn't try to run your code yet, but I have two remarks/questions:

* Why do you have `]` at the end of your regexp?

typo you're right, thx

* You should check `l_reg.match_count >= 2`, one for the entire string, and one for the substring.

You are right, I corrected it but am with the same problem... match_count is at 0...

ebezault commented 5 years ago

I must say that I never used [:alnum:]. Perhaps there is a bug here. Can you try to replace it with [a-zA-Z0-9] to see if it works better?

ebezault commented 5 years ago

It could be that you need to write [[:name:]]. I think I read that once in some PCRE doc.

ebezault commented 5 years ago

Here: https://www.pcre.org/original/doc/html/pcresyntax.html#SEC8

phgachoud commented 5 years ago

Mac_regex: STRING = "^([0-9]{8})_([a-zA-Z0-9]{2}[-:][a-zA-Z0-9]{2}[-:][a-zA-Z0-9]{2}[-:][a-zA-Z0-9]{2}[-:][a-zA-Z0-9]{2}[-:][a-zA-Z0-9]{2})_.*"

solved my issue, I had both a trailing ] @ the end, and the alnum didn't work.

Thx for your help!