JSFiddle - React, Tailwind, and code Playground
by mjmitche
HTML
<h1>
Searching strings with Regular Expressions</h1>
<p id="sourceText">
I really like JavaScript. It's a fun, versatile language to program in. In fact,
I'd have to say that JavaScript is probably my all-time favorite programming
language. I think that everyone should learn how to program in JavaScript!</p>
<form method="post">
<input name="Button1" type="button" value="Find" id="btnFind" /></form>
JavaScript
function findString(sourceString, patternToFind) {
var result = sourceString.search(patternToFind);
if (result == -1)
alert("Pattern not found");
else alert("pattern was found at position:" + result);
}
function countMatches(sourceString, patternToFind, patLength) {
}
function doSearch() {
findString(document.getElementById('sourceText').innerHTML, /javascript/i);
countMatches(document.getElementById('sourceText').innerHTML,/javascript/, 10);
}
window.onload = function() {
document.getElementById('btnFind').onclick = doSearch;
}