Regular Expression, taking numbers between two pre-defined texts

4

I need to remove números from a string . The string follows a pattern:

http://www.meudominio.com/1789519-texto

The number will always be between / and -

I have been able to arrive at the following formula:

/ \ d + (? = -)

The problem is that / comes together, and I did not want it, I know I can easily cut it from string , but I'd really like to know how I can remove it from the result using the expression. >     

asked by anonymous 03.09.2015 / 19:08

1 answer

5

The regular expression is correct. You just have to group the desired result and select it:

    var re = new Regex(@"/(\d+)(?=-)");
    var match = re.Match("http://www.meudominio.com/1789519-texto");
    Console.WriteLine(match.Groups[1]);

match.Groups[0] is the integer expression found. The next indices are the groups, separated individually.

I made you a Fiddle .

    
03.09.2015 / 19:19