E
E
Eugene2015-09-28 17:17:38
Regular Expressions
Eugene, 2015-09-28 17:17:38

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'/>

I forgot to clarify, you need a regular expression that is not tied to some kind of programming language
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Ineshin, 2015-09-28
@IonDen

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

S
Sanan Yuzb, 2015-09-28
@Sanan07

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 question

Ask a Question

731 491 924 answers to any question