How to validate Date with Regex?

2

I'm trying to catch a date inside a string using regex, but when I try to retrieve the part of the string it returns me the following error:

  

parsing "\ RATE: ([\ d /] +)" - Unrecognized escape sequence   \ T.

 match = Regex.Match(sbDados2.ToString(), @"\TARIFA:([\d\/]+)");

if (match.Success)
{
    objDocInterfDoc.inicioVigencia = Validacao.ConverterCampoDateTime(new Entrada
    {
        Conteudo = Funcoes.RemoverEspacos(match.Groups[1].Value)
    }).Data;
}

My string:

  

{BUDGET NUMBER} 11727497 ~ INSURANCE PROPOSAL: ISSUE: ORIGIN N. PROPOSED COMPANY ~ GENERAL INSURANCE CITY OF GENERAL INSURANCE ~ 06/06/2016 ~ 69 - 63703827 ~ AVENIDA RIO BRANCO, 1489 - ELOSSEES ~ RENOVA PORTO SEGURO APOLLO ~ TYPE OF INSURANCE: 68 - 759817 ~ RENOVACAO PORTO ~ SÃO PAULO - CEP 01205-905 ~ WEBSITE: WWW.POROSEGURO.COM.BR ~ DAY 24 HOUR OF THE DAY ~ TARIFF: 08/06/2016 ~ MAY / 2016 ~ REGISTRATION CODE TO SUSEP 05886 ~ UP TO 24H OF THE DAY ~ PRINT: ~ 08/06/2017 ~ 08/06/2016 - 09: 26: 12 ~ CNPJ 61,198,164 / 0001-60 ~ SUSEP N .: 15414.000573 / 2006-42}

I want to recover the part RATE: 06/08/2016.

When I try to do it through regex101 , it validates that part.

    
asked by anonymous 13.06.2016 / 23:04

1 answer

6

Just remove this character (the backslash - \ ), if I understand correctly what you need, your regex does not need it to work.

The example below works fine

var sbDados2 = "TARIFA:25/04/2016";     
var match = Regex.Match(sbDados2.ToString(), @"TARIFA:([\d\/]+)");

See dotNetFiddle

    
13.06.2016 / 23:17