Unit - 4
Unit - 4
Modifier Description
i Perform case-insensitive matching
Perform a global match (find all matches
g rather than stopping after the first
match)
m Perform multiline matching
• <!DOCTYPE html>
• <html>
• <body>
• <h2>JavaScript Regular Expressions</h2>
• <p>Do a case-insensitive search for "MCA" in a
string:</p>
• <p id="demo"></p>
• <script>
• let text = "MCA STUDENTS";
• let result = text.match(/mca/i);
• document.getElementById("demo").innerHTML = result;
• </script> </body> </html>
• <!DOCTYPE html>
• <html>
• <body>
• <h2>JavaScript Regular Expressions</h2>
• <p>Do a global search for "is" in a string:</p>
• <p id="demo"></p>
• <script>
• let text = "Is this. all there is?";
• let result = text.match(/is/g);
• document.getElementById("demo").innerHTML = result;
• </script> </body> </html>
• <!DOCTYPE html>
• <html> <body>
• <h2>JavaScript Regular Expressions</h2>
• <p>Do a multiline search for "our" at each line in a
string:</p>
• <p id="demo"></p>
• <script>
• let text = "\n our students \n our class?";
• let result = text.match(/our/m);
• document.getElementById("demo").innerHTML = "Result
is: " + result;
• </script> </body> </html>
Asynchronous GET/POST using XMLHttpRequest
To send a request to a server, open() and send() methods of the
XMLHttpRequest object can be used as follows:
var xhttp = new XMLHttpRequest();
xhttp.open("", "ajax_info.txt", true);
xhttp.send();
❖ Method ❖ Description
❖ Specifies the type of request
The file can be any kind of file, like .txt and .xml, or
server scripting files like .asp and .php (which can
perform actions on the server before sending the
response back).
• Server requests should be sent asynchronously.
• The async parameter of the open() method should be
set to true:
xhttp.open("GET", "ajax_test.asp", true);