Using regex to extract date for valid_upto field from bank's webpage

Prasun Kumar prasun.code at gmail.com
Thu Jun 11 05:52:02 BST 2020


>
> You should really change it for beauty of the code.


Okay, on it. Thanks for the help.

Prasun

On Thu, 11 Jun 2020 at 10:13, Thomas Baumgart <thb at net-bembel.de> wrote:

> On Donnerstag, 11. Juni 2020 05:04:20 CEST Prasun Kumar wrote:
>
> > I did it using this:
> > string(REGEX MATCH "Bankleitzahlendateien - gültig vom ([^ ]*)" FILE_DATE
> >  "${DATA}")
> >     if(FILE_DATE)
> >         string(REPLACE "Bankleitzahlendateien - gültig vom " "" FILE_DATE
> > "${FILE_DATE}")
> >     endif()
>
> That indeed looks a bit awkward. Thinking about it, I would use this
>
>   string(REGEX MATCH "([0-9\.]+)" FILE_DATE ${FILE_DATA})
>
> to extract the date from the filename. If you really want to make sure
> the filename matches the whole pattern, you could use this two step
> approach:
>
>   string(REGEX MATCH "Bankleitzahlendateien - gültig vom ([^ ]*)"
> FILE_DATE ${DATA})
>   string(REGEX MATCH "([0-9\.]+)" FILE_DATE ${FILE_DATE})
>
> The first regex makes sure that the full pattern matches and the
> second extracts the date from it.
>
>
> > But anyway, thanks. It will help me next time.
>
> You should really change it for beauty of the code.
>
>
> > BTW is this feature mentioned somewhere in the CMake documentation?
>
> From https://cmake.org/cmake/help/v3.0/command/string.html
>
> ()        Saves a matched subexpression, which can be referenced
>           in the REGEX REPLACE operation. Additionally it is saved
>           by all regular expression-related commands, including
>           e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).
>
> --
>
> Regards
>
> Thomas Baumgart
>
> https://www.signal.org/       Signal, the better WhatsApp
> -------------------------------------------------------------
> Linux & Open Source Software - aaah, the sweet smell of 'Free'dom
> -------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-finance-apps/attachments/20200611/21126b3a/attachment.htm>


More information about the Kde-finance-apps mailing list