Search code examples
regexregular-language

Regex only 14 numbers


I have the following text:

DiretorioXmlImpressao=C:\\Program Files (x86)\\TESTE\\XmlImpressao\\08187168000160\\

I would like to select all but the CNPJ(14-character sentence at the end of the text), and so I tried the following regular expression:

DiretorioXmlImpressao=[^0-9]+

Returned:

DiretorioXmlImpressao=C:\\Program Files (x

but I expected: 08187168000160


Sorry guys, i have a few experience with regex, I just don't express myself very well.

I want in fact do this return:

DiretorioXmlImpressao=C:\\Program Files (x)\\TESTE\\XmlImpressao\\

cause i want just only the 14-character and the \, for i can use in this replace. This is working execept when have numbers in the path like that"x86".

regexp_replace(teste,'DiretorioXmlImpressao=[^0-9]+',E'DiretorioXmlImpressao=P:\\TESTE\\XmlImpressao\\','ig');

the final expect result of my regex and replace is this below

DiretorioXmlImpressao=P:\\TESTE\\XmlImpressao\\08187168000160\\

Thanks!


Solution

  • I've test this like bobble bubble said to do

    DiretorioXmlImpressao=.*\D(?=\d)
    

    and it's working like i wanted to

    DiretorioXmlImpressao=C:\\Program Files (x86)\\TESTE\\XmlImpressao\\
    

    Thanks for all!