Solved

javascript regular expression assign everything after underscore to a variable

Posted on 2012-03-09
4
406 Views
Last Modified: 2012-03-09
Hello!

I'm trying to create a super simple regular expression! I just want to assign to a variable everything after an underscore. it will be a counter- number, then and underscore then a fedex or ups tracking code.

var linkId = 3_1Z6656460348661915;

//incomprehensible regular expression magic 

var trackingNumber = 1Z6656460348661915;

Open in new window


I'm grateful for any help! Thanks!
0
Comment
Question by:hibbsusan
  • 2
4 Comments
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 37703466
Try:

var trackingNumber = /_(.*)/[1];

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 37703527
var linkId = 3_1Z6656460348661915;
var trackingNumber = linkId.split("_")[0]; // faster than regex
//or with a regex
//var trackingNumber = linkId.match(/_(.*)/)[1]; // kaufmed's illustration ?

Open in new window

0
 

Author Closing Comment

by:hibbsusan
ID: 37703546
thanks!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 37703666
you're welcome!

var linkId = 3_1Z6656460348661915;
var trackingNumber = linkId.split("_")[1]; // ^_^

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now