regex - C# Getting value between two same characters -


usually, can string value between 2 characters. question is, how value between 2 same characters.

for example:

string full_value = "http://stackoverflow.com/questions/9367119/title-goes-here"; 

in example, how can extract value 9367119 entire string?

the solution use doesn't work since 9367119 has same / characters right , left of it.

here's have far:

this works values doesn't have 2 same characters left , right. such as: /dog\ can replace / , \ solution

public static string between(string full_value, string a, string b) {         int posa = full_value.indexof(a);         int posb = full_value.lastindexof(b);         if (posa == -1)         {             return "";         }         if (posb == -1)         {             return "";         }         int adjustedposa = posa + a.length;         if (adjustedposa >= posb)         {             return "";         }         return full_value.substring(adjustedposa, posb - adjustedposa);     } 

you split , relevant part:

string s = "http://stackoverflow.com/questions/9367119/title-goes-here"; string[] sp = s.split('/'); console.writeline(sp[4]); 

ideone demo.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -