Extract text from a string using regex

Hi There,

I’m trying to extract some text from a string but it doesn’t seems to match anything.

*** Settings ***
Documentation     Demo showing how to extract text from a string

Library     String

*** Tasks ***
Extract text from string
    Get string

Get string
    ${url}  set variable
        ...  https://adsl.free.fr/facture_pdf.pl?id=10634115&idt=UgtIzj9YwPZI9H1iS88CJZIf9uZm1kKl6tb2uMaeB4CWWzActsaFi5ycTCqsjCS4KypkdTfP1JFPoRzcn9suaR&mois=202203&no_facture=1096254246
    ${invoiceName}   Get Regexp Matches   ${url}    /mois=(\d{6})&no_facture=(\d*)/
    Log   ${invoiceName}

Any idea what’s wrong?

PS: I’ve tried my regex in regex101 and both group are matching.

Best regards,

Hi @Gael

This works

${invoiceName} Get Regexp Matches ${url} .*mois=(\\d{6})&no_facture=(\\d*).* 1 2

It returns this: [('202203', '1096254246')]

Read more about Get Regexp Matches and keyword Should Match Regexp (which explains more about using regular expression with Robot Framework syntax.


I’ve forgot to escape my special characters…
\d instead of \d
Silly me.

Thanks for your time