Answer the question
In order to leave comments, you need to log in
How to cut out the necessary numbers from the link?
Hello,
I need help with a regular expression. You need to get the number of the picture, which is present in the file name and is separated from other numbers by an underscore. In this example, it is number 08.
<img src='http://site.com/galleries/179606_08.jpg'/>
Answer the question
In order to leave comments, you need to log in
This can be checked from without regex: jsfiddle.net/afbccz3h/1
var img = document.getElementById('img'),
url = img.getAttribute('src');
function getNum (url) {
var parts = url.split('/'),
len = parts.length,
name = parts[len - 1],
num = name.split('_')[1].split('.')[0];
return num;
}
var num = getNum(url);
console.log(num); // 08
string tag = "<img src='http://site.com/galleries/1.79.6.06_238.jpg'/>";
string[] reg = Regex.Split(tag, "[_.]");
Console.WriteLine(reg[reg.Length-2]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question