0

I don't have any experience with Regex. How do I extract the value of FieldInternalName from a string like below? Need only the value without quotes.

var idString = '<!--  FieldName="App" FieldInternalName="Application" FieldType="SPFieldLookup" -->';

2 Answers 2

2

would something like this work for ya?

var idString = '<!--  FieldName="App" FieldInternalName="Application" FieldType="SPFieldLookup" -->';
var fieldInternalName = idString.match(/FieldInternalName="(.*?)"/i)[1];
alert(fieldInternalName);
Sign up to request clarification or add additional context in comments.

Comments

0

It is very easy to set up a simple expression that will "capture" the contents of FieldInternalName:

<!--.*?\bFieldInternalName="([^"]+)".*?-->

Demo


This expression works by looking for:

  • <!--
  • 0+ characters (.*?)
  • FieldInternalName=" (preceded by a word boundary,\b, so that you don't match something like FakeFieldInternalName=")
  • 1+ non-" characters ([^"]+)
  • "
  • 0+ characters (.*?)
  • -->

Using RegExp.prototype.exec(), we can extract the contents of this match:

var idRegex = /<!--.*?\bFieldInternalName="([^"]+)".*?-->/,
    idString = '<!--  FieldName="App" FieldInternalName="Application" FieldType="SPFieldLookup" -->';

var matches = idRegex.exec(idString);
console.log(matches[1]);
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

1 Comment

Didn't know there was such a tool with so much detail.Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.