What's the code look like? Like, I don't know anything, but I can make a regular expression that would do that, in the flavor I know (though it's more like "know").
Let's see if I can get this to look right in a comment... the HTML is two textareas and a button that calls doStuff when clicked.
Also, looking at it again I can't remember why I defined a couple of variables the way I did. But it works, so whatever.
<script type="text/javascript">
document.getElementById('txtIn').focus();
function doStuff() {
var input=document.getElementById('txtIn');
var output=document.getElementById('txtOut');
var strInputText=input.value;
var strOutputText="";
var str1="";
if (strInputText==='') {
output.value='';
return;
}
var strArray=strInputText.split("\n");
var strNext="";
for (var i = 0; i < strArray.length; i++) {
strNext=strArray[i];
str1="<a href=\"http://www.flickr.com/photos/";
if ((strNext).indexOf(str1) > -1) {
strNext=doRegEx(strNext);
}
if (strOutputText.length > 0) {
strOutputText = strOutputText + "\n";
}
strOutputText=strOutputText + strNext;
}
output.value=strOutputText;
}
function doRegEx(strText) {
//<a href="http://www.flickr.com/photos/18343898@N05/9511658613/" title="0022happensalot by napoleonicmonkeygirl, on Flickr"><img src="http://farm4.staticflickr.com/3690/9511658613_40e4aac74a_o.jpg" width="550" height="375" alt="0022happensalot"></a>
//replace the a title with nothing
// title="00xxxsomethinghere by napoleonicmonkeygirl, on Flickr"
strText=strText.replace(/ title="[\s\S]*?on Flickr"/g, "");
//replace the img alt with border=0
strText=strText.replace(/alt="[\s\S]*?"/g, "border=\"0\"");
//image tags should close dammit
strText=strText.replace("\"></a>", "\" /></a>");
return strText;
}
</script>
Yeah, that looks right. Now that I replaced all the angle brackets with < and >
Ah. Well, as could have been expected, I understand none of that except the stuff that looks like a regular expression. So I guess what I'm asking is, why didn't you just do a search and replace? Although I do remember running into some problems with it in Notepad++.
Well, you'd have to do two passes, but the first would be (and this is in EditPad's syntax but I think these are pretty standard): title=".+? by napoleonicmonkeygirl, on Flickr" Which you'd replace with nothing, and the second would be: alt=".+?" Which you'd replace with: border="0"
If I'm misinterpreting something horribly, it's because it's half past four and I should really be asleep.
I think the fault is more with me because, despite not having the excuse of being awake at an insane time, I never thought about using regex in an actual text editor until now (I use notepad++ but I'm pretty sure it has regex functionality). I still don't feel too bad for being too dumb to think of that, though, because at least this way all the work is done and I don't have to enter the strings correctly into anything -- just paste, click, and copy the results.
I don't think that's an indication of you being dumb, I'm assuming you're just used to writing code more, whereas using regular expressions in a text editor is literally the most advanced thing I know how to do. And yeah, Notepad++ has them, but Scintilla's implementation is weird - I remember not being able to do certain things because there are characters reserved for Scintilla stuff. I can't remember what they were or what it was that I couldn't do, I just know back then I gave up and stuck with the limited stuff Word had to offer, which ended up being enough. I really only use them for messing around with ebooks or OCRed books, and for stripping away timecodes out of subtitle files.
I am actually kind of TERRIBLE at regular expressions, like, I don't really get them at all no matter how many tutorials I read. Writing code is easier for me. (We'll ignore the fact that it took twice as long to write that code as it should have because I kept trying to use jQuery [which is a javascript library that makes certain things easier] before finally realizing that it hadn't been included even though I told netbeans to include it. So I said fuckit and rewrote to not depend on jQuery at all since why pull in an entire library for so little code in the first place.)
For what it's worth, I am also terrible, and this is after like six abortive attempts that I am at a level where I know juuuust enough to do the stuff I want to do, and not a bit more. And writing code is way more useful a skill.
Man I really wish LJ would allow me to edit a comment once someone else has replied to it. That long line of text in my javascript is starting to drive me insane.
What I like is that when I put all-caps English into the From box, the results in the To were TOTALLY DIFFERENT. And the word "sounds" remained untranslated.
no subject
Date: 2013-08-17 11:48 pm (UTC)no subject
Date: 2013-08-18 12:44 am (UTC)Also, looking at it again I can't remember why I defined a couple of variables the way I did. But it works, so whatever.
Yeah, that looks right. Now that I replaced all the angle brackets with < and >
no subject
Date: 2013-08-18 12:52 am (UTC)no subject
Date: 2013-08-18 01:19 am (UTC)title="some text here that changes on every picture by napoleonicmonkeygirl on Flickr"
and the string
alt="some other text here that changes on every picture"
Which is impossible to find-and-replace unless I update the find string (2 x the number of pictures which is usually around 80) times.
no subject
Date: 2013-08-18 01:33 am (UTC)title=".+? by napoleonicmonkeygirl, on Flickr"
Which you'd replace with nothing, and the second would be:
alt=".+?"
Which you'd replace with:
border="0"
If I'm misinterpreting something horribly, it's because it's half past four and I should really be asleep.
no subject
Date: 2013-08-18 04:38 am (UTC)no subject
Date: 2013-08-18 11:43 am (UTC)And yeah, Notepad++ has them, but Scintilla's implementation is weird - I remember not being able to do certain things because there are characters reserved for Scintilla stuff. I can't remember what they were or what it was that I couldn't do, I just know back then I gave up and stuck with the limited stuff Word had to offer, which ended up being enough. I really only use them for messing around with ebooks or OCRed books, and for stripping away timecodes out of subtitle files.
no subject
Date: 2013-08-18 01:58 pm (UTC)no subject
Date: 2013-08-19 02:32 pm (UTC)no subject
Date: 2013-08-19 11:34 pm (UTC)no subject
Date: 2013-08-19 11:35 pm (UTC)no subject
Date: 2013-08-19 11:43 pm (UTC)or apparently
IYI, TAMAMEN MAKUL GELIYOR
thank you google translate, I'm sure I didn't at all just tell someone that I wanted to spank his sister with with a slice of bologna
no subject
Date: 2013-08-19 11:48 pm (UTC)no subject
Date: 2013-08-19 11:53 pm (UTC)no subject
Date: 2013-08-19 11:56 pm (UTC)