regex - Extracting values from a regular expression & removing brackets in C# -
i'm trying take string of html , match instance of [image, h, w] h , w integers can 1200.
this first foray learning regular expressions. here have far:
regex r = new regex(@"\image, (\d+?), (\d+?)\]"); match match = r.match(controltext);
but in regex tester not selecting final bracket, , in code not matching string should.
so output want 'image, h, w', , there want parse h & w , store them in variable.
i'm junior developer in second week @ first job , think i'm spending way time trying figure out. appreciated.
tuple<int, int>[] imagesizes = (from match match in new regex(@"\[image, (\d+), (\d+)\]").matches(controltext) select new tuple<int, int>( int.parse(match.groups[1].value), int.parse(match.groups[2].value))).toarray();
example: string controltext = "[image, 1200, 100]abacaldjfal; jk[image, 289, 400]";
imagesizes
[1200, 100], [289, 400]
.
edit: since seems there 1 instance of markup, can following:
match match = new regex(@"\[image, (\d+), (\d+)\]").match(controltext); int h = int.parse(match.groups[1].value); int w = int.parse(match.groups[2].value);
example: string controltext = "[image, 1200, 100]abcadjfklajdfad;afdh";
h
1200
, w
100
.
Comments
Post a Comment