Replacing Strings at specific locations

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












text = "Donc", "j'obtiens", "<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>",
"<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"


Now my question is:



  1. How can I get the position of in the list of every object that starts with <i>?


  2. How can I replace the <i> at the start of that object and the </i> at the end of that object by another string ?


By "object" I really mean a list object: for instance, I don't want the <i> and </i> to be replaced in "ça veut dire que si je multiplie par <i>c</i>", since this object of the list does not start with an <i>.



EDIT: To clear any confusion, here is how the text could look like afterwards:



"Donc", "j'obtiens", "REPLACE([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE",
"REPLACEaᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"









share|improve this question























  • Could try something like Position[text, s_String /; StringMatchQ[s, "<i>*</i>"]], but that won't catch the last two items with italics tags since they don't actually "start with <i>", as the criterion you mentioned.
    – J. M. is computer-less♦
    27 mins ago










  • @J.M.iscomputer-less That's actually perfect ! Maybe I was not clear enough, but I don't want to catch "<i>" where the sentence does not start with "<i>". Can you post it as an answer ? Then I can accept it, if you also know how to replace the "<i>" and "</i>" in the found sentences.
    – james
    23 mins ago










  • If just for replacement, it seems no need to get their positions.
    – Î‘λέξανδρος Ζεγγ
    22 mins ago










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    22 mins ago










  • You did not mention what kind of replacement you wanted to do. Is it derived from the matching string, or something completely different?
    – J. M. is computer-less♦
    20 mins ago














up vote
1
down vote

favorite












text = "Donc", "j'obtiens", "<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>",
"<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"


Now my question is:



  1. How can I get the position of in the list of every object that starts with <i>?


  2. How can I replace the <i> at the start of that object and the </i> at the end of that object by another string ?


By "object" I really mean a list object: for instance, I don't want the <i> and </i> to be replaced in "ça veut dire que si je multiplie par <i>c</i>", since this object of the list does not start with an <i>.



EDIT: To clear any confusion, here is how the text could look like afterwards:



"Donc", "j'obtiens", "REPLACE([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE",
"REPLACEaᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"









share|improve this question























  • Could try something like Position[text, s_String /; StringMatchQ[s, "<i>*</i>"]], but that won't catch the last two items with italics tags since they don't actually "start with <i>", as the criterion you mentioned.
    – J. M. is computer-less♦
    27 mins ago










  • @J.M.iscomputer-less That's actually perfect ! Maybe I was not clear enough, but I don't want to catch "<i>" where the sentence does not start with "<i>". Can you post it as an answer ? Then I can accept it, if you also know how to replace the "<i>" and "</i>" in the found sentences.
    – james
    23 mins ago










  • If just for replacement, it seems no need to get their positions.
    – Î‘λέξανδρος Ζεγγ
    22 mins ago










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    22 mins ago










  • You did not mention what kind of replacement you wanted to do. Is it derived from the matching string, or something completely different?
    – J. M. is computer-less♦
    20 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











text = "Donc", "j'obtiens", "<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>",
"<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"


Now my question is:



  1. How can I get the position of in the list of every object that starts with <i>?


  2. How can I replace the <i> at the start of that object and the </i> at the end of that object by another string ?


By "object" I really mean a list object: for instance, I don't want the <i> and </i> to be replaced in "ça veut dire que si je multiplie par <i>c</i>", since this object of the list does not start with an <i>.



EDIT: To clear any confusion, here is how the text could look like afterwards:



"Donc", "j'obtiens", "REPLACE([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE",
"REPLACEaᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"









share|improve this question















text = "Donc", "j'obtiens", "<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>",
"<i>aᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.</i>", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"


Now my question is:



  1. How can I get the position of in the list of every object that starts with <i>?


  2. How can I replace the <i> at the start of that object and the </i> at the end of that object by another string ?


By "object" I really mean a list object: for instance, I don't want the <i> and </i> to be replaced in "ça veut dire que si je multiplie par <i>c</i>", since this object of the list does not start with an <i>.



EDIT: To clear any confusion, here is how the text could look like afterwards:



"Donc", "j'obtiens", "REPLACE([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - 
[Beta]₂) + ... + aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE",
"REPLACEaᵢ₁([Alpha]₁ - [Beta]₁) + aᵢ₂([Alpha]₂ - [Beta]₂) + ... +
aₙ₁([Alpha]ₙ - [Beta]ₙ) = bᵢ - bᵢ = 0.REPLACE", "Donc en particulier",
"ça veut dire que si je multiplie par <i>c</i>", "pour tout nombre réel
<i>c</i>"






string-manipulation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 mins ago

























asked 34 mins ago









james

639418




639418











  • Could try something like Position[text, s_String /; StringMatchQ[s, "<i>*</i>"]], but that won't catch the last two items with italics tags since they don't actually "start with <i>", as the criterion you mentioned.
    – J. M. is computer-less♦
    27 mins ago










  • @J.M.iscomputer-less That's actually perfect ! Maybe I was not clear enough, but I don't want to catch "<i>" where the sentence does not start with "<i>". Can you post it as an answer ? Then I can accept it, if you also know how to replace the "<i>" and "</i>" in the found sentences.
    – james
    23 mins ago










  • If just for replacement, it seems no need to get their positions.
    – Î‘λέξανδρος Ζεγγ
    22 mins ago










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    22 mins ago










  • You did not mention what kind of replacement you wanted to do. Is it derived from the matching string, or something completely different?
    – J. M. is computer-less♦
    20 mins ago
















  • Could try something like Position[text, s_String /; StringMatchQ[s, "<i>*</i>"]], but that won't catch the last two items with italics tags since they don't actually "start with <i>", as the criterion you mentioned.
    – J. M. is computer-less♦
    27 mins ago










  • @J.M.iscomputer-less That's actually perfect ! Maybe I was not clear enough, but I don't want to catch "<i>" where the sentence does not start with "<i>". Can you post it as an answer ? Then I can accept it, if you also know how to replace the "<i>" and "</i>" in the found sentences.
    – james
    23 mins ago










  • If just for replacement, it seems no need to get their positions.
    – Î‘λέξανδρος Ζεγγ
    22 mins ago










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    22 mins ago










  • You did not mention what kind of replacement you wanted to do. Is it derived from the matching string, or something completely different?
    – J. M. is computer-less♦
    20 mins ago















Could try something like Position[text, s_String /; StringMatchQ[s, "<i>*</i>"]], but that won't catch the last two items with italics tags since they don't actually "start with <i>", as the criterion you mentioned.
– J. M. is computer-less♦
27 mins ago




Could try something like Position[text, s_String /; StringMatchQ[s, "<i>*</i>"]], but that won't catch the last two items with italics tags since they don't actually "start with <i>", as the criterion you mentioned.
– J. M. is computer-less♦
27 mins ago












@J.M.iscomputer-less That's actually perfect ! Maybe I was not clear enough, but I don't want to catch "<i>" where the sentence does not start with "<i>". Can you post it as an answer ? Then I can accept it, if you also know how to replace the "<i>" and "</i>" in the found sentences.
– james
23 mins ago




@J.M.iscomputer-less That's actually perfect ! Maybe I was not clear enough, but I don't want to catch "<i>" where the sentence does not start with "<i>". Can you post it as an answer ? Then I can accept it, if you also know how to replace the "<i>" and "</i>" in the found sentences.
– james
23 mins ago












If just for replacement, it seems no need to get their positions.
– Î‘λέξανδρος Ζεγγ
22 mins ago




If just for replacement, it seems no need to get their positions.
– Î‘λέξανδρος Ζεγγ
22 mins ago












@ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
– james
22 mins ago




@ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
– james
22 mins ago












You did not mention what kind of replacement you wanted to do. Is it derived from the matching string, or something completely different?
– J. M. is computer-less♦
20 mins ago




You did not mention what kind of replacement you wanted to do. Is it derived from the matching string, or something completely different?
– J. M. is computer-less♦
20 mins ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










Cases[text, _String?(StringMatchQ["<i>*"]), Infinity]



"aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.", "aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0."




StringReplace[text, 
StartOfString ~~ "<i>" ~~ s__ ~~ "</i>" ~~ EndOfString :> "REPLACE" <> s <> "REPLACE"]



"Donc", "j'obtiens", "REPLACEaᵢ₁(α₁ - β₁) +
aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ
= 0.REPLACE", "REPLACEaᵢ₁(α₁ - β₁) + aᵢ₂(α₂ -
β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.REPLACE",
"Donc en particulier", "ça veut dire que si je multiplie par
c", "pour tout nombre réel c"







share|improve this answer






















  • Thanks a lot ! This works nicely and is comprehensible.
    – james
    11 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    10 mins ago

















up vote
2
down vote













For replacement, (e.g., below is just to delete them)



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "$1"]


The key point is to locate the (sub)strings (but not by knowing the positions explicitly), having achieved which, one can do whatever one wants to them :).




For the updated detailed request



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "REPLACE$1REPLACE"]





share|improve this answer






















  • This replaces the "<i>" and "<i/>" but kills the rest of the text.
    – james
    17 mins ago










  • @james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
    – Î‘λέξανδρος Ζεγγ
    16 mins ago











  • Thank you very much for your answer !
    – james
    11 mins ago

















up vote
1
down vote













StringReplace["this is the <i>old text</i>" , 
"<i>" ~~ ___ ~~ "</i>" -> "new text"]





share|improve this answer




















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    14 mins ago










  • That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
    – J. M. is computer-less♦
    12 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    9 mins ago










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183972%2freplacing-strings-at-specific-locations%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Cases[text, _String?(StringMatchQ["<i>*"]), Infinity]



"aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.", "aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0."




StringReplace[text, 
StartOfString ~~ "<i>" ~~ s__ ~~ "</i>" ~~ EndOfString :> "REPLACE" <> s <> "REPLACE"]



"Donc", "j'obtiens", "REPLACEaᵢ₁(α₁ - β₁) +
aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ
= 0.REPLACE", "REPLACEaᵢ₁(α₁ - β₁) + aᵢ₂(α₂ -
β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.REPLACE",
"Donc en particulier", "ça veut dire que si je multiplie par
c", "pour tout nombre réel c"







share|improve this answer






















  • Thanks a lot ! This works nicely and is comprehensible.
    – james
    11 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    10 mins ago














up vote
2
down vote



accepted










Cases[text, _String?(StringMatchQ["<i>*"]), Infinity]



"aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.", "aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0."




StringReplace[text, 
StartOfString ~~ "<i>" ~~ s__ ~~ "</i>" ~~ EndOfString :> "REPLACE" <> s <> "REPLACE"]



"Donc", "j'obtiens", "REPLACEaᵢ₁(α₁ - β₁) +
aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ
= 0.REPLACE", "REPLACEaᵢ₁(α₁ - β₁) + aᵢ₂(α₂ -
β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.REPLACE",
"Donc en particulier", "ça veut dire que si je multiplie par
c", "pour tout nombre réel c"







share|improve this answer






















  • Thanks a lot ! This works nicely and is comprehensible.
    – james
    11 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    10 mins ago












up vote
2
down vote



accepted







up vote
2
down vote



accepted






Cases[text, _String?(StringMatchQ["<i>*"]), Infinity]



"aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.", "aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0."




StringReplace[text, 
StartOfString ~~ "<i>" ~~ s__ ~~ "</i>" ~~ EndOfString :> "REPLACE" <> s <> "REPLACE"]



"Donc", "j'obtiens", "REPLACEaᵢ₁(α₁ - β₁) +
aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ
= 0.REPLACE", "REPLACEaᵢ₁(α₁ - β₁) + aᵢ₂(α₂ -
β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.REPLACE",
"Donc en particulier", "ça veut dire que si je multiplie par
c", "pour tout nombre réel c"







share|improve this answer














Cases[text, _String?(StringMatchQ["<i>*"]), Infinity]



"aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.", "aᵢ₁(α₁ - β₁) + aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0."




StringReplace[text, 
StartOfString ~~ "<i>" ~~ s__ ~~ "</i>" ~~ EndOfString :> "REPLACE" <> s <> "REPLACE"]



"Donc", "j'obtiens", "REPLACEaᵢ₁(α₁ - β₁) +
aᵢ₂(α₂ - β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ
= 0.REPLACE", "REPLACEaᵢ₁(α₁ - β₁) + aᵢ₂(α₂ -
β₂) + ... + aₙ₁(αₙ - βₙ) = bᵢ - bᵢ = 0.REPLACE",
"Donc en particulier", "ça veut dire que si je multiplie par
c", "pour tout nombre réel c"








share|improve this answer














share|improve this answer



share|improve this answer








edited 15 mins ago

























answered 20 mins ago









kglr

165k8188388




165k8188388











  • Thanks a lot ! This works nicely and is comprehensible.
    – james
    11 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    10 mins ago
















  • Thanks a lot ! This works nicely and is comprehensible.
    – james
    11 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    10 mins ago















Thanks a lot ! This works nicely and is comprehensible.
– james
11 mins ago




Thanks a lot ! This works nicely and is comprehensible.
– james
11 mins ago












@james, my pleasure. Thank you for the accept.
– kglr
10 mins ago




@james, my pleasure. Thank you for the accept.
– kglr
10 mins ago










up vote
2
down vote













For replacement, (e.g., below is just to delete them)



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "$1"]


The key point is to locate the (sub)strings (but not by knowing the positions explicitly), having achieved which, one can do whatever one wants to them :).




For the updated detailed request



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "REPLACE$1REPLACE"]





share|improve this answer






















  • This replaces the "<i>" and "<i/>" but kills the rest of the text.
    – james
    17 mins ago










  • @james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
    – Î‘λέξανδρος Ζεγγ
    16 mins ago











  • Thank you very much for your answer !
    – james
    11 mins ago














up vote
2
down vote













For replacement, (e.g., below is just to delete them)



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "$1"]


The key point is to locate the (sub)strings (but not by knowing the positions explicitly), having achieved which, one can do whatever one wants to them :).




For the updated detailed request



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "REPLACE$1REPLACE"]





share|improve this answer






















  • This replaces the "<i>" and "<i/>" but kills the rest of the text.
    – james
    17 mins ago










  • @james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
    – Î‘λέξανδρος Ζεγγ
    16 mins ago











  • Thank you very much for your answer !
    – james
    11 mins ago












up vote
2
down vote










up vote
2
down vote









For replacement, (e.g., below is just to delete them)



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "$1"]


The key point is to locate the (sub)strings (but not by knowing the positions explicitly), having achieved which, one can do whatever one wants to them :).




For the updated detailed request



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "REPLACE$1REPLACE"]





share|improve this answer














For replacement, (e.g., below is just to delete them)



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "$1"]


The key point is to locate the (sub)strings (but not by knowing the positions explicitly), having achieved which, one can do whatever one wants to them :).




For the updated detailed request



StringReplace[text, RegularExpression["^<i>(.*)</i>$"] -> "REPLACE$1REPLACE"]






share|improve this answer














share|improve this answer



share|improve this answer








edited 5 mins ago

























answered 20 mins ago









Αλέξανδρος Ζεγγ

2,5241826




2,5241826











  • This replaces the "<i>" and "<i/>" but kills the rest of the text.
    – james
    17 mins ago










  • @james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
    – Î‘λέξανδρος Ζεγγ
    16 mins ago











  • Thank you very much for your answer !
    – james
    11 mins ago
















  • This replaces the "<i>" and "<i/>" but kills the rest of the text.
    – james
    17 mins ago










  • @james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
    – Î‘λέξανδρος Ζεγγ
    16 mins ago











  • Thank you very much for your answer !
    – james
    11 mins ago















This replaces the "<i>" and "<i/>" but kills the rest of the text.
– james
17 mins ago




This replaces the "<i>" and "<i/>" but kills the rest of the text.
– james
17 mins ago












@james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
– Î‘λέξανδρος Ζεγγ
16 mins ago





@james StringReplace is better here, which leaves strings unmatched untouched. I modified it.
– Î‘λέξανδρος Ζεγγ
16 mins ago













Thank you very much for your answer !
– james
11 mins ago




Thank you very much for your answer !
– james
11 mins ago










up vote
1
down vote













StringReplace["this is the <i>old text</i>" , 
"<i>" ~~ ___ ~~ "</i>" -> "new text"]





share|improve this answer




















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    14 mins ago










  • That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
    – J. M. is computer-less♦
    12 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    9 mins ago














up vote
1
down vote













StringReplace["this is the <i>old text</i>" , 
"<i>" ~~ ___ ~~ "</i>" -> "new text"]





share|improve this answer




















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    14 mins ago










  • That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
    – J. M. is computer-less♦
    12 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    9 mins ago












up vote
1
down vote










up vote
1
down vote









StringReplace["this is the <i>old text</i>" , 
"<i>" ~~ ___ ~~ "</i>" -> "new text"]





share|improve this answer












StringReplace["this is the <i>old text</i>" , 
"<i>" ~~ ___ ~~ "</i>" -> "new text"]






share|improve this answer












share|improve this answer



share|improve this answer










answered 15 mins ago









LouisB

4,1941616




4,1941616











  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    14 mins ago










  • That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
    – J. M. is computer-less♦
    12 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    9 mins ago
















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    14 mins ago










  • That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
    – J. M. is computer-less♦
    12 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    9 mins ago















This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
– james
14 mins ago




This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
– james
14 mins ago












That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
– J. M. is computer-less♦
12 mins ago




That's what I was asking you about earlier @james. So, what you want is a derived string and not an independent string. That's because replacing <i>stuff</i> with stuff and replacing <i>stuff</i> with something needs different approaches.
– J. M. is computer-less♦
12 mins ago












@J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
– james
9 mins ago




@J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
– james
9 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183972%2freplacing-strings-at-specific-locations%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?