- What are the JavaScript's built-in methods for performing pattern-matching ?
- Explain different type of Regular Expression?
- (i)Character Classes
- (ii)Predefined Character Classes
- (iii) Repetition Quantifiers
- (iv)Position Anchors (Flags)
- (v)Pattern Modifiers (Flags)
- (vi)Alternation
- (vii)Grouping
- (viii)Word Boundaries
- find particular words is available in a string or no of words matches in string ?
- how to find and replace space with a hyphen character in a string using regular expression with the JavaScript replace() method:
- how to find and replace sentence words in comma using split regular expression with the JavaScript replace() method:
- how to display sentence words using for loop.
- example will match only those names in the names array which start with the letter "J".
- find particular words is available in a string or no of words matches in string with g and i modifiers ,Pattern Modifiers Flags?
- find particular words is available in a string or no of words matches in string with g and i modifiers ,Pattern Modifiers Flags?
- find any of 3 words matches in string?
- JavaScript Match Words Starts or Ends with a Pattern Using Regular Expression
-
What are the JavaScript's built-in methods for performing pattern-matching ?click here for Refrence
- Explain different type of Regular Expression? (i)Character Classes (ii)Predefined Character Classes (iii) Repetition Quantifiers (iv)Position Anchors (Flags) (v)Pattern Modifiers (Flags) (vi)Alternation (vii)Grouping (viii)Word Boundaries click here for Refrence
-
find particular words is available in a string or no of words matches in string ?click here for solution
-
how to find and replace space with a hyphen character in a string using regular expression with the JavaScript replace() method:
click here for solution
-
how to find and replace sentence words in comma using split regular expression with the JavaScript replace() method:
how to display sentence words using for loop
click here for solution
-
how to find and replace sentence words in comma using split regular expression with the JavaScript replace() method:
how to display sentence words using for loop
click here for solution
15.example will match only those names in the names array which start with the letter "J"
-
how to find and replace sentence words in comma using split regular expression with the JavaScript replace() method:
how to display sentence words using for loop
click here for solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Match Strings Beginning with Specific Characters Using Regular Expression</title>
</head>
<body>
<script>
var regex = /^J/;
var names = ["James Bond", "Clark Kent", "John Rambo"];
// Loop through names array and display matched names
for(var name of names) {
if(regex.test(name)) {
document.write("<p>" + name + "</p>")
}
}
</script>
</body>
</html>
output:
James Bond
John Rambo
- find particular words is available in a string or no of words matches in string with g and i modifiers (Pattern Modifiers (Flags)?click here for solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Match a Pattern in a Multiline String Using Regular Expression</title>
</head>
<body>
<script>
var str = "Color red is more visible than \ncolor blue in daylight.";
var regex1 = /^color/gi;
var regex2 = /^color/gim;
var matches = str.match(regex1); // pattern matching without multiline flag
document.write("<p>Found " + matches.length + " matches: " + matches + "</p>");
console.log(matches);
matches = str.match(regex2); // pattern matching with multiline flag
document.write("<p>Found " + matches.length + " matches: " + matches + "</p>");
console.log(matches);
</script>
</body>
</html>
output:
Found 1 matches: Color
Found 2 matches: Color,color
- find any of 3 words matches in string?click here for solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Specify Alternative Version of a Pattern in a Regular Expression</title>
</head>
<body>
<script>
var regex = /fox|dog|cat/;
var str = "The quick brown fox jumps over the lazy dog.";
var matches = str.match(regex);
document.write("Matches the substring: " + matches);
console.log(matches);
// expected output: ["fox", index: 16, ...]
</script>
</body>
</html>
output:
Matches the substring: fox
- JavaScript Match Words Starts or Ends with a Pattern Using Regular Expressionclick here for solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Match Words Starts or Ends with a Pattern Using Regular Expression</title>
</head>
<body>
<script>
var regex = /(\bcar\w*)/g;
var str = "Words begining with car: cart, carrot, cartoon. Words ending with car: oscar, supercar.";
var replacement = '<b>$1</b>';
// Highlights the words beginning with car in bold
var result = str.replace(regex, replacement);
document.write(result);
</script>
</body>
</html>
output:
Words begining with car: cart, carrot, cartoon. Words ending with car: oscar, supercar.
Top comments (0)