Solved

JavaScript/REGEX: First word that begins with

Posted on 2013-06-17
1
388 Views
Last Modified: 2013-06-17
Using JavaScript and REGEX, how can I get the first word that begins with something?

This does NOT work:

var xyz = 'hello id123 world';
alert ( ( xyz.match(/id+[0-9](\b|$)/) ) ? xyz.match(/id+[0-9](\b|$)/)[0] : '');
// should alert 123

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
ID: 39253702
The "+" should be after the "]", not before the "[".
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

14 Experts available now in Live!

Get 1:1 Help Now