Forums: Front End:

 

Using regex for a replace() in javascript

first
 

Technomancer Using regex for a replace() in javascript

I'm sure that this is simple:

I have a requirement to parse some input text that has BB type code (e.g [img src=""]) and output as html tags.

So I simply need to replace "[" and "]" with "<" and ">" respectively in one regex expression, I don't need clever checking to determine type of tags.

My regex brain is slightly befuddled by a rather nice claret I had with lunch and this ain't working:

outputStr = inputStr.replace(/\[(.*?)\]/g, "<$1>")


Alternately anyone know of a very cheap or ideally free XML editor which will automatically enode HTML tags entered as data in a node. Has to be very simple for my client to use!


Everyone should believe in something
I believe I'll have another drink
quote
 

Technomancer

Solution worked out:

outputStr = inputStr.replace(/\[(.*?)\]/g, "<\$1\>")


Everyone should believe in something
I believe I'll have another drink
quote
 
first
 

Forums: Front End: Using regex for a replace() in javascript

 
New Post
 
You must be logged in to post