Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript Example 1: Regular Expressions

const string = 'Find me';
const pattern = /me/;
// search if the pattern is in string variable
const result1 = string.search(pattern);
console.log(result1); // 5
// replace the character with another character
const string1 = 'Find me';
string1.replace(pattern, 'found you'); // Find found you

// splitting strings into array elements
const regex1 = /[s,]+/;
const result2 = 'Hello world! '.split(regex1);
console.log(result2); // ['Hello', 'world!', '']

// searching the phone number pattern
const regex2 = /(d{3})D(d{3})-(d{4})/g;
const result3 = regex2.exec('My phone number is: 555 123-4567.');
console.log(result3); // ["555 123-4567", "555", "123", "4567"]
Comment

PREVIOUS NEXT
Code Example
Javascript :: Split string into words, without punctuation 
Javascript :: join two arrays in js 
Javascript :: why array.map returns undefined 
Javascript :: js empty map 
Javascript :: react code 
Javascript :: javascript iterate over map values 
Javascript :: onclick hold react 
Javascript :: how to useeffect for unmount 
Javascript :: install express generator 
Javascript :: javascript check if array is empty or null or undefined 
Javascript :: js get copied text 
Javascript :: ./node_modules/bootstrap/dist/js/bootstrap.bundle.js 
Javascript :: download datepicker js 
Javascript :: puppeteer 
Javascript :: nestjs init 
Javascript :: import and export type in js 
Javascript :: angularjs format number thousands separator 
Javascript :: elapsed time function() {math javascript 
Javascript :: delete item from array 
Javascript :: Uncaught TypeError: theme.spacing is not a function 
Javascript :: disable zoom in app 
Javascript :: javascript round to nearest integer 
Javascript :: in vs of javascript 
Javascript :: Simple interest in javascript 
Javascript :: javascript error try catch 
Javascript :: jquery datatable draw false 
Javascript :: how to find last element of an array 
Javascript :: encode password javascript 
Javascript :: express send pdf to view 
Javascript :: replacing a value in string using aregular expression pyhton 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =