Regex does not work

Hello Guys,

few days ago a had got a regex formula to get a telephone number from a string it works in uipath but when i used it in a c# code:

string labphone = System.Text.RegularExpressions.Regex.Match(item, @“(?<=l:|l :).[0-9\s0-9\W]”).Value;
it did not work, also when testing the regex alone:

can you provide the sample and string ?

tél : 01 88 33 32 88 fax : 01 49 41 21 15 Dr J. FRRR Dr P. ASSS

@abdel,

Try with this regex expression, I hope the “fax” text will there always.

(?<=tél :|tél:\s).*?(?=fax)


it’s working fine for me @abdel

could you give me the link to the regex tester?

also i had tryed in the c#:

System.Text.RegularExpressions.Regex.Match(item, @“(?<=”+row[8]+“:|”+row[0]+" :).[0-9\s0-9\W]").Value;

but there is an error: unrecognized escape sequence

HI @abdel,

please refer below URL for testing purpose

Regards,
Arivu

You haven’t closed the first “(” braces correctly… we can see two open “(” but only one “)”.

hello,

i know that it is not a c# forim but i got the Following error:
: 'Impossible to cast a ‘System.DBNull’ object in ‘System.String’ type

when running the code:

static void Main(string args)
{
DataTable dtexcel = new DataTable();
Console.WriteLine(“Hello world”);
string PathFolder = “---------” ;
foreach (string file in Directory.EnumerateFiles(PathFolder, “*.txt”))
{
string labphone= null;
string labname = null;
string Analysisdate= null;

            dtexcel = exceldata("-------.xlsx");
       

            string[] splitted;
            List<string> List = new List<string>();
            string text = System.IO.File.ReadAllText(file);
            splitted = text.Split('\r');

            foreach (string item in splitted)
            {
               

                foreach (DataRow row in dtexcel.Rows)
                {
                    if (item.Contains((string)row[8]))
                    {
                        Console.WriteLine("row" + row[8]);
                        labphone = System.Text.RegularExpressions.Regex.Match(item, @"(?<=l:|l :).[0-9\s0-9\W]*").Value;

                        List.Add(labphone);
                    }

                }
            }
            string extractedlabphone = List.First();
            Console.WriteLine("labphone" + extractedlabphone);
            //Fin d'extraction de télèphone
            foreach (string item in splitted)
            {

                foreach (DataRow row in dtexcel.Rows)
                {
                    Console.WriteLine("Row(0)" + row[0]);
                    if (item.Contains((string)row[0]))
                    {

                        labname = item;
                        
                    }

                }
            }
            Console.WriteLine("labname" +labname);



            Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();

        }
    }

You should try this amazing service GoogleFaxFree. This will help you how to send gmail fax free basically Google Fax Free offers an amazing option. You must try. All the best!