Faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 7 people (29%) answered Yes
Recently 2 of 7 people (29%) answered Yes


How do I concatenate a string variable to a regular expression. e.g var re = /^-?(\d/ and str=","

Oct 7th, 2001 05:57
Colin Fraser, Sam maran,

I am not sure exactly what it is that you are getting at but if I am
reading you right try : 
<script >
var re=/^-?(\d/ 
var str=","   
document.write("The end result is "+re+" "+str)
although I would probably be more likely to write this one as 
document.write("The end result is "+re+", ")
depending on what is to folow the statement. 
As a general coding tip, when I am coding something for the first time,
I write the resultant string out how I want it to appear, then just
replace what is required with the above formatting. Use as many
variables as you need to. Also if the sentence is going to appear more
than once, what can you place into constant strings? I might try
something like : 
<script >
var const="The end result is "
var re="/^-?(\d/" 
var str=", "   
again, depending on what is to follow. 
I hope this has been helpful.