javascript - regex - get numbers after certain character string -


i have text string can number of characters attach order number end. can pluck off order number when need use again. since there's possibility number variable length, regular expression catch's after = sign in string ?order_num=

so whole string be

"aijfoi aodsifj adofija afdoiajd?order_num=3216545" 

i've tried use online regular expression generator no luck. can please me extracting number on end , putting them variable , put comes before ?order_num=203823 own variable.

i'll post attempts of own, foresee failure , confusion.

var s = "aijfoi aodsifj adofija afdoiajd?order_num=3216545";  var m = s.match(/([^\?]*)\?order_num=(\d*)/); var num = m[2], rest = m[1]; 

but remember regular expressions slow. use indexof , substring/slice when can. example:

var p = s.indexof("?"); var num = s.substring(p + "?order_num=".length), rest = s.substring(0, p); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -