Solved

javascript regular expression assign everything after underscore to a variable

Posted on 2012-03-09
4
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 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