Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a json object where one of the parameters is as below

"https://d1swzmic55peuz.cloudfront.net/7.0.1-5xTesi.101/",

or
"https://d1swzmic44peuz.cloudfront.net/7.0.0-bathrolls.103/"


From all the above I need someting like this 7.0.1.101 or
7.0.0.103

What I have tried:

I tried using subtring to remove the text prior to / and then regex but did not manage to filter out the value.
C#
Configuration resource = JsonConvert.DeserializeObject<configuration>(content);
string[] line = resource.ResourceRoot.Split('/');
var regex = new Regex(@"[\d\.]"); var matches = regex.Matches(line[3]);
string version = string.Empty;
foreach (Match match in matches)
{ 
     version = string.Join(version, match);
}
Posted
Updated 16-Nov-22 4:12am
v3
Comments
CHill60 16-Nov-22 3:59am    
Share the code you used
datt265 16-Nov-22 4:14am    
Configuration resource = JsonConvert.DeserializeObject<configuration>(content);
string[] line = resource.ResourceRoot.Split('/');
var regex = new Regex(@"[\d\.]");
var matches = regex.Matches(line[3]);
string version = string.Empty;
foreach (Match match in matches)
{
version = string.Join(version, match);
}

CHill60 16-Nov-22 5:22am    
I have added this code to your question. To add extra details to a post, click on the green "Improve question" link

1 solution

Try this:
C#
string reg = @"(?<=https://.*?/)(\d+\.\d+\.\d+)(?:[^\.]+?)(\.\d+)";
string inp = @"https://d1swzmic55peuz.cloudfront.net/7.0.1-5xTesi.101/";
Match m = Regex.Match(inp, reg);
if (m.Success && m.Groups.Count == 3)
    {
    Console.WriteLine($"{m.Groups[1].Value}{m.Groups[2].Value}");
    }
If you are going to use Regular expressions, get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900