i ask a question yesterday. how to remove the tag name only, and remove the tag name including the content yesterday using jquery.
and the answer is using regex.
can someone explain the code below for me just the regex part?
i already read some articles about regex but i think i dont fully understand it clearly.
if possible, i want to convert it to c# code, but i can't do it yet because i dont fully understand the code. thank you
first code
$(function() {
function removeNode(str, nodeName) {
var pattern = '<'+nodeName+'>[\\s\\w]+<\/'+nodeName+'>';
var regex = new RegExp(pattern, 'gi');
return str.replace(regex, '').replace(/^\s*[\r\n]/gm, '');
}
what i dont undertand in the first code is where does the 'gi' come from? and the return
var regex = new RegExp(pattern, 'gi');
return str.replace(regex, '').replace(/^\s*[\r\n]/gm, '');
second code
$(function() {
function removeNodeButRetain(str, nodeName) {
var pattern = '<\/?'+nodeName+'>';
var regex = new RegExp(pattern, 'gi');
return str.replace(regex, '').replace(/^\s*[\r\n]/gm, '');
}
what i dont understand is the
var regex = new RegExp(pattern, 'gi');
return str.replace(regex, '').replace(/^\s*[\r\n]/gm, '');
third code
jQuery(document).ready(function(){
textval = $('textarea').val();
textnewval = textval.replace('Para TextBreak="No"', 'p').replace('/Para', '/p');
if(textnewval.indexOf('Italic') >= 0) //If Italic
{
EmphasisAttr = 'Italic';
textnewval = textnewval.replace('Emphasis Type="'+EmphasisAttr+'"', 'i').replace('/Emphasis', '/i');
}
if(textnewval.indexOf('Bold') >= 0) //If Bold
{
EmphasisAttr = 'Bold';
textnewval = textnewval.replace('Emphasis Type="'+EmphasisAttr+'"', 'b').replace('/Emphasis', '/b');
}
if(textnewval.indexOf('Underline') >= 0) //If underline
{
EmphasisAttr = 'Underline';
textnewval = textnewval.replace('Emphasis Type="'+EmphasisAttr+'"', 'u').replace('/Emphasis', '/u');
}
$('textarea').val(textnewval);
alert($('textarea').val());
});
System.Xmlnamespace to manipulate the xml