0

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

3 Answers 3

1

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

string value = Regex.Matches( inputString, @"\$\('#hotel'\)\.val\((\d+)\)", RegexOptions.None )[0].Groups[1].Value;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much, it worked well, as Im also new to regex, could you suggest me how to get the number of 160 from this url ? reservas.hoteldirecto.es/2/front/index/hotel/160 Thanks @Derek
Regex.Matches( inputString, @".+/(\d+)", RegexOptions.None )[0].Groups[1].Value;
1

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

2 Comments

Thank you very much for your help, could you please suggest me the idea if I wish to get the number 3999 in this URL ? vinccihoteles.com/busqueda/(idPartner)/VINCCI/(codigoHotel)/…
This is a different question, please ask about that (after trying something yourself) in another post to get help from the community.
-1

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);

1 Comment

You also need to add escaped parenthesis to match the one from val(...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.