I have below text and remove comments text get rest of it.
var text ='<!-- FieldName="Title"
FieldInternalName="Title"
FieldType="SPFieldText"
-->
Test Project'
I just get text="Test Project"
. How to do that?
I have below text and remove comments text get rest of it.
var text ='<!-- FieldName="Title"
FieldInternalName="Title"
FieldType="SPFieldText"
-->
Test Project'
I just get text="Test Project"
. How to do that?
You can use built-in HTML parsing to do this. Append your text to an empty div, then use jQuery's .text()
function to get the text in the div
.
Here's a runnable snippet:
var text ='<!-- FieldName="Title" FieldInternalName="Title" FieldType="SPFieldText" -->Test Project';
var newText = $("<div/>").append(text).text();
alert(newText);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
This is just basic Regex. Here some documentation, and an example.
http://jsbin.com/wezozejusu/1/edit?js,console
var text = '<!-- FieldName="Title" FieldInternalName="Title" FieldType="SPFieldText" --> Test Project';
var after = text.replace(/<!--(.*)-->[\s]*/g, '');
console.log(after);