Solved

javascript regular expression assign everything after underscore to a variable

Posted on 2012-03-09
4
418 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

635 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