JavaScript Code

JavaScript String match()


String match()

str.match(regexp)
  • str is a string
  • match is function name
  • regexp is a regular expression. if string is provided for this parameter, then the string is converted to regular expression

match() method returns an array of values that are matched in the string str for the matching regexp

Examples

1. find all matchings in the string str with the regular expression /apple/ig in str. this regular expression matches for the string 'apple' globally with case -insenitive

let str = 'apple banana Apple mango';
let matchings = str.match(/apple/ig);
console.log(matchings);


Copyright @2022