hello ya'll,

i'm looking for help with using regex for finding a name like (v/d haren). can someone help with solving this

Like this?:

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace DW_420137_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         List<string> lst_strSurNames = new List<string>()
         {
            "v/d Haren",
            "van den Haren",
            "Jones",
            "von den Haren",
            "Smith",
            "von den Berg",
            "van den Berg",
            "v/d Berg"
         };

         Regex rxTargetSurNames = new Regex(@"v.{0,3}\bd.{0,3} [a-z]{1,}");
         foreach(string s in lst_strSurNames)
         {
            if (rxTargetSurNames.IsMatch(s.ToLower()))
            {
               Console.WriteLine(s);
            }
         }
      }
   }
}

Edited 4 Years Ago by thines01: added picture

Attachments DW_420137.jpg 12.36 KB

Same outcome. Same Regex. Different technique.

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;

namespace DW_420137_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         Regex rxTargetSurNames = new Regex(@"v.{0,3}\bd.{0,3} [a-z]{1,}");
         new List<string>()
         {
            "v/d Haren",
            "van den Haren",
            "Jones",
            "von den Haren",
            "Smith",
            "von den Berg",
            "van den Berg",
            "v/d Berg"
         }.Where(s => rxTargetSurNames.IsMatch(s.ToLower())).ToList().ForEach(s => Console.WriteLine(s));
      }
   }
}

Edited 4 Years Ago by thines01: formatting

This article has been dead for over six months. Start a new discussion instead.