4

How to find substring between the two words using jQuery

 1 year ago
source link: https://www.laravelcode.com/post/how-to-find-substring-between-the-two-words-using-jquery
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to find substring between the two words using jQuery

  8843 views

  2 years ago

jQuery

Use the JavaScript match() method

You can use the JavaScript match() method to extract substring between two words.

The following example will show you how to extract substring between the two words using the match() method and a simple regular expression pattern.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Get Substring Between Two Words</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            var myStr = "The quick brown fox jumps over the lazy dog.";
            var subStr = myStr.match("quick(.*)lazy");
            alert(subStr[1]);
        });
    });
</script>
</head>
<body>
    <p>Click the following button to get the substring between the word "quick" and "lazy" from the string "The quick brown fox jumps over the lazy dog."</p>
    <button type="button">Get Substring</button>
</body>
</html>
Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK