Friday, 25 March 2011

web ex6:-


SOURCE CODE:
<html>
<title>
FINDS REGULAR EXPRESSIONS AND REPLACING REQ
</title>
<h3 align="center">
pattern replacement using regular expressions
</h3>
<script language="javascript">
function search()
{
if(myform.initialising.value)
{

}
else
{
window.alert("string not is there");
return;
}
if(myform.substring.value)
{

}
else
{
window.alert("substring not is there");
return;
}
var att="",st=myform.initialising.value,
sr=myform.substring.value,
re=myform.replacestring.value;
var reg=new RegExp(sr,att);
if(st.match(reg))
{
 myform.searchresult.value="pattern found";
 window.alert("pattern found" +sr);
}
else
{
myform.searchresult.value="pattern not found";
window.alert("pattern not found"  +sr);
}
}
function replace()
{
var att="",st=myform.initialising.value,
sr=myform.substring.value,
re=myform.replacestring.value;
var reg=new RegExp(st,att);
if(myform.replacestring.value)
{
window.alert("replacestring is there");
}
else
{
window.alert("replacestring not is there");
return;
}
if(st.match(reg))
{
myform.searchresult.value="pattern found";
 window.alert("pattern found"+re);
}
else
{
myform.searchresult.value="pattern not found";
window.alert("pattern not found");
}
myform.replaceresult.value=(re);
}
</script>
<pre>
<form name="myform">
Enter a string:::<input type=text name="initialising">
Enter a substring to search:::<input type=text name="substring">
Enter a replacement string:::<input type=text name="replacestring">
<input type=button value="search string" onclick="search()">
<input type=button value="replace string" onclick="replace()">
result of search:::<input type=text name="searchresult">
result of replacement:::<input type=text name="replaceresult">
<input type=reset value="reset">
</form>
</pre>
</html>

No comments:

Post a Comment