Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
-3
rated 0 times [  0] [ 3]  / answers: 1 / hits: 50291  / 12 Years ago, mon, june 4, 2012, 12:00:00

I have a text string that can be any number of characters that I would like to attach an order number to the end. Then I can pluck off the order number when I need to use it again. Since there's a possibility that the number is variable length, I would like to do a regular expression that catch's everything after the = sign in the string ?order_num=



So the whole string would be



aijfoi aodsifj adofija afdoiajd?order_num=3216545


I've tried to use the online regular expression generator but with no luck. Can someone please help me with extracting the number on the end and putting them into a variable and something to put what comes before the ?order_num=203823 into its own variable.



I'll post some attempts of my own, but I foresee failure and confusion.


More From » regex

 Answers
4
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 that regular expressions are slow. Use indexOf and substring/slice when you can. For example:



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

[#85149] Sunday, June 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Mon, Jun 22, 20, 00:00, 4 Years ago
;