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

Thomas Baumgart thb at net-bembel.de
Thu Jun 11 05:43:22 BST 2020


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 --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 868 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-finance-apps/attachments/20200611/0b3c4aea/attachment.sig>


More information about the Kde-finance-apps mailing list