I would like to save a substring to a javascript variable using regex unless there is a different/easier way. For example i have a link like this: http://www.youtube.com/wa
Efficient:
variable = variable.substring(variable.indexOf('?v=')+3) // First occurence of ?v=
Regular expression:
variable = variable.replace(/.*\?v=/, '') // Replace last occurrence of ?v= and any characters before it (except \r or \n) with nothing. ? has special meaning, that is why the \ is required
variable = variable.replace(/.*?\?v=/, '') // Variation to replace first occurrence.