-1

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?

James123
  • 11,184
  • 66
  • 189
  • 343

2 Answers2

1

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>
Dave
  • 10,748
  • 3
  • 43
  • 54
0

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);
Oka
  • 23,367
  • 6
  • 42
  • 53
  • It's best [not to try parsing HTML with RegEx](http://stackoverflow.com/a/1732454/361762), especially when running in a browser, which can do the work for you. – Dave May 15 '15 at 19:40