473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formatter using Javascript

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, "&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

Aug 18 '05 #1
2 1698
VK

ja************@clovertechnologies.com wrote:
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.


Your're asking a working solution rather than an advise. This may be
the reason you did not get an answer. How about a minimum code sample:

1) Here is my RegExp, it should find/replace such and such sequences.
2) It fails on this and this sequences.
3) How to narrow my RegExp?

And one RegExp per round would be plenty OK.
;-)

Aug 19 '05 #2
Hi There,
Thanks for guidance . I should post it to some newsgroup related to
parsers can you guide me on such a parser.
With Warm regards
Jatinder Singh

Aug 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christopher Pragash | last post by:
Hello All, Recently I had posted a message to forum requesting assistance to resolve a security issueI was facing in .NET Framework 1.1, the error being "Because of Security Restrictions, the...
8
by: John Dalberg | last post by:
I have spent 1/2 hour looking for a Javascript formatter with no luck. I am using a tool that produces Javascript statements in one long string and it's hard to read. Any recommendations? I see...
9
by: John Dalberg | last post by:
I am using a utility that creates Javascript. However the javascript is one hugely long stream of characters. Is there a utility that can format the Javascipt so that it put each statement in a...
4
by: Patrick De Ridder | last post by:
Which library should I include for the formatter in formatter.Serialize(output, record); Many thanks. -- Patrick De Ridder ngmail@freeler.nl
4
by: Andreas Huber | last post by:
Hello there I need to serialize/deserialize some pretty simple data structures (no inheritance, few has relationships, ~20 classes) in three formats. One is XML (structure is not important as...
2
by: Nadav | last post by:
Hi, I am trying to create a custom formatter ( such as the binary formatter ), I can't figure out where do I bind the input Data Stream with the SerializationInfo object info how should i create...
1
by: Edward Yang | last post by:
When it comes to ViewState in ASP.NET, I have a mixed feeling of both love and hate. For love, it simplifies many aspects of common tasks; for hate, it bloats web pages with large amount of cryptic...
1
by: andrew | last post by:
I was earlier trying to persist a windows forms control to disk using the binary formatter class. I have devised a workaround, however I have Classes added in as references to my project which...
3
by: mistral | last post by:
I there any good javascript formatter tool? (format javascript accurately, etc) Mistral
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.