vendredi 19 juin 2020

Regex - Extract string patterns

I have many strings like these

/test/v1/3908643GASF/item
/test/v1/343569/item/AAAS45663/document
/test/v2/field/1230FRE/item
...

For each one I need to extract the defined pattern like these

/test/v1/{Value}/item
/test/v1/{Value}/item/{Value}/document
/test/v2/field/{Value}/item

The value can be a guid or something else, Can I match the given string patterns with input paths with regex?

I wrote just this code but I don't konw how to match input paths with patterns. The result should be the pattern. Thank you

string pattern1 = "/test/v1/{Value}/item";
string pattern2 = "/test/v1/{Value}/item/{Value}/document";
string pattern3 = "/test/v2/field/{Value}/item";

List<string> paths = new List<string>();
List<string> matched = new List<string>();    

paths.Add("/test/v1/3908643GASF/item");
paths.Add("/test/v1/343569/item/AAAS45663/document");
paths.Add("/test/v1/343569/item/AAAS45664/document");
paths.Add("/test/v1/123444/item/AAAS45688/document");
paths.Add("/test/v2/field/1230FRE/item");


foreach (var path in paths)
{


}

Aucun commentaire:

Enregistrer un commentaire