[Solved] Regular Expression in javascript for ’45 minutes’


This code will help you I guess.

<!DOCTYPE html>
<html>
<body>

<p>Search for 45 minutes in the text in the next paragraph:</p>

<p id="p01">45 minutes</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    text = document.getElementById("p01").innerHTML;
    document.getElementById("demo").innerHTML = /[0-9]{2}\sminutes/.exec(text);
}
</script>

</body>
</html>

Here [0-9]{2} means that allow any number with two digits. \s means whitespace character and minutes is the text you want to be found in it.

If you want more basic information on regex expressions, you can find it here: Regex Expressions

0

solved Regular Expression in javascript for ’45 minutes’