Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js regex last occurrence

// JS REGEX FOR LAST OCCURENCE:
const str = "This is the first KEYWORD and this is the last KEYWORD";
str.match(/(KEYWORD)(?!.*1)/g)
//=> ["KEYWORD"]

// Using lastIndexOf():
str.lastIndexOf("KEYWORD")
//=> 47
 
PREVIOUS NEXT
Tagged: #js #regex #occurrence
ADD COMMENT
Topic
Name
1+3 =