Reputation: 43
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" -->';
Upvotes: 0
Views: 90
Reputation: 20486
It is very easy to set up a simple expression that will "capture" the contents of FieldInternalName
:
<!--.*?\bFieldInternalName="([^"]+)".*?-->
This expression works by looking for:
<!--
.*?
)FieldInternalName="
(preceded by a word boundary,\b
, so that you don't match something like FakeFieldInternalName="
)"
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>
Upvotes: 0
Reputation: 126
would something like this work for ya?
var idString = '<!-- FieldName="App" FieldInternalName="Application" FieldType="SPFieldLookup" -->';
var fieldInternalName = idString.match(/FieldInternalName="(.*?)"/i)[1];
alert(fieldInternalName);
Upvotes: 2