RegExp Help!

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","smalld­atetime","\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, "&nbsp;$1&nbsp;");


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top