J
jsfromynr
Hi All,
I am trying to Format a given TSQL code so that it is well indented and
easy to understand
It is moderately working with simple scripts, but where the script
involve some part of keywords (like endrosmentnumber has end in it)it
fails
Please guide me with the regular Expression stuff so that I can make it
work.
<textarea rows=20 cols=80 name=t1>
</textarea>
<br>
<input type=button onclick="format()" Value = "Format It">
<br>
<span id=t2 name=t2>
</span>
<script type="text/javascript">
function format()
{
var keywords = new Array("Begin Trans","Begin","case");
var keywords2 = new Array("End Trans","End");
var keywords3 = new Array("=",",");
var keywords4 = new
Array("int","datetime","smalldatetime","\bfrom\b");
var keywords5 = new Array("--","set","select");
var keywords6 = new Array(",");
//var str = "Create Procedure p1 as Begin Begin Trans declare @and int
select * from p1 End Trans
End";
var str
str = t1.value
var re = new RegExp("(" + keywords.join("|") + ")", "ig");
str = str.replace(re, "<ol>$1<ol>");
var re2 = new RegExp("(" + keywords2.join("|") + ")", "ig");
str = str.replace(re2, "</ol>$1</ol>");
re2 = new RegExp("(" + keywords3.join("|") + ")", "ig");
str = str.replace(re2, " $1 ");
re2 = new RegExp("(" + keywords4.join("|") + ")", "ig");
str = str.replace(re2, "$1<br>");
re2 = new RegExp("(" + keywords5.join("|") + ")", "ig");
str = str.replace(re2, "<br>$1");
//document.write(str)
t2.innerHTML = str
}
</script>
With Warm regards
Jatinder Singh
I am trying to Format a given TSQL code so that it is well indented and
easy to understand
It is moderately working with simple scripts, but where the script
involve some part of keywords (like endrosmentnumber has end in it)it
fails
Please guide me with the regular Expression stuff so that I can make it
work.
<textarea rows=20 cols=80 name=t1>
</textarea>
<br>
<input type=button onclick="format()" Value = "Format It">
<br>
<span id=t2 name=t2>
</span>
<script type="text/javascript">
function format()
{
var keywords = new Array("Begin Trans","Begin","case");
var keywords2 = new Array("End Trans","End");
var keywords3 = new Array("=",",");
var keywords4 = new
Array("int","datetime","smalldatetime","\bfrom\b");
var keywords5 = new Array("--","set","select");
var keywords6 = new Array(",");
//var str = "Create Procedure p1 as Begin Begin Trans declare @and int
select * from p1 End Trans
End";
var str
str = t1.value
var re = new RegExp("(" + keywords.join("|") + ")", "ig");
str = str.replace(re, "<ol>$1<ol>");
var re2 = new RegExp("(" + keywords2.join("|") + ")", "ig");
str = str.replace(re2, "</ol>$1</ol>");
re2 = new RegExp("(" + keywords3.join("|") + ")", "ig");
str = str.replace(re2, " $1 ");
re2 = new RegExp("(" + keywords4.join("|") + ")", "ig");
str = str.replace(re2, "$1<br>");
re2 = new RegExp("(" + keywords5.join("|") + ")", "ig");
str = str.replace(re2, "<br>$1");
//document.write(str)
t2.innerHTML = str
}
</script>
With Warm regards
Jatinder Singh