Reputation: 5
I'm using Feedroll for showing RSS entries on my Tumblr.
Let's say I have:
document.write('<li class="rss-item"><a class="rss-item" href="http://mywebsite.com/arandomlink" target="_self"> [element1] element2 element3 element4</a><br />');
document.write('</li>');
element1 is a text "Thisismytext" (fixed length : 7)
element2 is a text "This Is My Text" (length not fixed)
element3 is a number "01" to "24" (fixed length : 2)
element4 is a text "THIS IS MY TEXT" (fixed length : 6 + space + 2)
(I have many entries and element1 and element4 don't change.)
I can't change the code from Feedroll or the titles of the entries.
Now, I would like to show my enrties ([element1] element2 element3 element4
) like element 2 - element 3
.
Example: [Thisismytext] This Is My Text 05 OTHER TEXT
to This Is My Text - 05
.
How do I do that?
I have tried split(), pop(), and substring() but I don't know how to use them.
And by the way, sorry for my English, I am French.
Upvotes: 0
Views: 73
Reputation: 1287
Assuming you don't receive the elements individually and are just getting a bunch of markup that you want to reformat...
If you are receiving the string of text and you want to strip out the different elements, you might want to use a regular expression to match the elements.
The following expression would just matches the text [element1] element2 element3 element4 with the constraints that you mentioned.
regular expression : /\[(.{7})\]\s(.*)\s([0-9]{0,2})\s(.*)/g
sample text : [Thisism] This Is My Text 02 OTHER TEXT
matches :
If you are receiving the full HTML string, you'd have to alter the regular expression to handle the html tags.
More info on regular expressions here : http://www.regular-expressions.info/tutorial.html
Upvotes: 1