bluewonder
bluewonder

Reputation: 777

Getting javascript text by RegEx C#

I have the html content with following value in javascript:

$('#hotel').val(9864);
var hotel_id = $('select#hotel option:selected').val();
$.ez( 'ezjscvincci::setHotelDetails', {arg1: hotel_id}, function( data )
{
    computeHotelAvailabilityLink();
});

now i want to get the 9864 ID out of those javascripts by Regex, could you suggest me an idea? Thanks

Upvotes: 0

Views: 58

Answers (3)

Derek
Derek

Reputation: 8763

This is the same as Robin's but with c#:

string value = Regex.Matches( inputString, @"\$\('#hotel'\)\.val\((\d+)\)", RegexOptions.None )[0].Groups[1].Value;

Upvotes: 1

Robin
Robin

Reputation: 9644

If you just want the id following the hotel part in this code snippet you can use something like:

\$\('#hotel'\).val\((\d+)\)

\d+ is a shortcut for [0-9] and your result will be in the first capturing group: http://regex101.com/r/wS7qH7

Upvotes: 1

Jonathan Hiben
Jonathan Hiben

Reputation: 553

You could simply use this :

Match match = Regex.Match(youString, @"val([0-9]*)");

And then get the value :

string value = match.Value; int numValue = int.Parse(value);

Upvotes: -1

Related Questions