- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to match strings that aren't entirely digits in JavaScript?
Let’s say the following is our complicated string −
var values = 'studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678"';
You can use regular expression to match strings. Following is the code −
Example
var regularExpression = /(?<=:)(?!(?:null|false|true|\d+),)[\w-]+(?=,)/g; var values = 'studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678"'; console.log("Original Value="+values); console.log("The string that are not entirely digits="); console.log(values.match(regularExpression));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo187.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo187.js Original Value=studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678" The string that are not entirely digits= [ '10001J-10001' ]
- Related Articles
- How to match strings that aren't entirely digits in JavaScript?
- How to match two strings that are present in one line with grep in Linux?
- How to match only digits in Python using Regular Expression?
- How to match digits using Java Regular Expression (RegEx)
- Find all strings that match specific pattern in a dictionary in C++
- How to match non-digits using Java Regular Expression (RegEx)
- How to match only non-digits in Python using Regular \nExpression?\n
- MySQL Regular expressions: How to match digits in the string with d?
- How to Match patterns and strings using the RegEx module in Python
- Regex to match lines containing multiple strings in Java
- C# Program to match all the digits in a string
- Function that parses number embedded in strings - JavaScript
- How do find out all elements that match a specific condition in JavaScript?
- How to concatenate several strings in JavaScript?
- How to generate random strings with upper case letters and digits in Python?
- Number of digits that divide the complete number in JavaScript

Advertisements