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♦
    20 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
    16 mins ago










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










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    15 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♦
    12 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♦
    20 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
    16 mins ago










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










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    15 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♦
    12 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 9 mins ago

























asked 27 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♦
    20 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
    16 mins ago










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










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    15 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♦
    12 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♦
    20 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
    16 mins ago










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










  • @ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
    – james
    15 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♦
    12 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♦
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♦
20 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
16 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
16 mins ago












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




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












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




@ΑλέξανδροςΖεγγ Okay, interesting. How would you do it then ?
– james
15 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♦
12 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♦
12 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
    4 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    3 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 :).






share|improve this answer






















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










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











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

















up vote
1
down vote













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




share




















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    6 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♦
    4 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    2 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
    4 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    3 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
    4 mins ago










  • @james, my pleasure. Thank you for the accept.
    – kglr
    3 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 8 mins ago

























answered 13 mins ago









kglr

165k8188388




165k8188388











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










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
















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










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















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




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












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




@james, my pleasure. Thank you for the accept.
– kglr
3 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 :).






share|improve this answer






















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










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











  • Thank you very much for your answer !
    – james
    3 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 :).






share|improve this answer






















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










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











  • Thank you very much for your answer !
    – james
    3 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 :).






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 :).







share|improve this answer














share|improve this answer



share|improve this answer








edited 3 mins ago

























answered 13 mins ago









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

2,5241826




2,5241826











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










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











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
















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










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











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















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




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












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





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













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




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










up vote
1
down vote













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




share




















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    6 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♦
    4 mins ago










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














up vote
1
down vote













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




share




















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    6 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♦
    4 mins ago










  • @J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
    – james
    2 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












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





share











share


share










answered 8 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
    6 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♦
    4 mins ago










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
















  • This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
    – james
    6 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♦
    4 mins ago










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















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




This replaces everything in between "<i>" and "<i/>". Please have a look at my example in the question.
– james
6 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♦
4 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♦
4 mins ago












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




@J.M.iscomputer-less I see. I guess I miscommunicated my answer. Thank you for the information.
– james
2 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













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery