• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

javascript regular expression assign everything after underscore to a variable

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
hibbsusan
Asked:
hibbsusan
  • 2
2 Solutions
 
käµfm³d 👽Commented:
Try:

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

Open in new window

0
 
leakim971PluritechnicianCommented:
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
 
hibbsusanAuthor Commented:
thanks!
0
 
leakim971PluritechnicianCommented:
you're welcome!

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

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now