- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Hi guys, I have a problem I am loading some text with HTML formating, the problem is that the formating is not normal HTML instead of using
<i></i> or <b></b>the text uses symbols like this is bold or ’’this text will be italic’’. The question is how can I change those into HTML tags? I need to know when the tag ends and when begins but the closing and opening symbols in text look exactly the same. Any ideas?
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Author had a Free File of the Month
- Bought between 1 and 9 items
- Exclusive Author
- Europe
- Has been a member for 3-4 years
- Referred between 10 and 49 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
You say the start and end symbols look the same, but what exactly do they look like? Can you give us a verbatim excerpt from the text?
Because you can likely still manage it with a regular expression or at worst a simple loop even though the start and end tokens the same. The only difference is that it would just fail harder if there was a syntax error in the text.
For example:
var str: String = 'Lorem ipsum sit amet dolor "this is italic" lorem ipsum'; var newStr: String = str.replace(/"(.*?)"/gs, '<i>$1</i>'); trace(newStr);
Does exactly what you need for if italics are always surrounded by a ”. The only difference between a properly thought out syntax (where beginning and ending tokens are different) is that if there’s a syntax error (using a quote where it shouldn’t be) it will throw off the formatting from that point in the text onward, whereas a properly designed syntax would only fail for the specific place where the error was.
EDIT : make sure to use the .*? instead of just .* like I originally posted, .* is a greedy match .*? is a lazy match and you need a lazy match for it to work right. And use /gs flags if you want it to work across multiple lines, only /g flag if you don’t.
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Hi, guys this text is driven from the Wikipedia API here you can see the formatting syntax http://www.mediawiki.org/wiki/Help:Formatting MBMedia I will check your solution seems it should work! 
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
var str:String = "[[something]]"; str = str.replace(/[[(.*?)]]/gs, '<a href="#">$1</a>'); trace(str) //what I get in trace is "[[something]]", why the brackets are not changed?
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Any idea why method replace doesn’t recognize square brackets( [ )? ? ;/
Because square brackets are part of RegExp syntax, so they need to be escaped if you want them interpreted as just characters in your pattern.
var str:String = "[[something]]"; str = str.replace(/\[\[(.*?)\]\]/gs, '<a href="#">$1</a>'); trace(str)
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
MBMedia said
Because square brackets are part of RegExp syntax, so they need to be escaped if you want them interpreted as just characters in your pattern.var str:String = "[[something]]"; str = str.replace(/\[\[(.*?)\]\]/gs, '<a href="#">$1</a>'); trace(str)
Great that works! 
Few more question, I want to change something from File: to | I am having trouble for example “File:this is a file.jpg|Something” to “
Something”
Also I am having trouble to change “heart”. into something like “heart”.
Additionally is there a way to remove white space + text from point to point or point to end of file?
P.S Never worked with such string replacement before sorry for all the questions.
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Also how to say that I want to replace from | to first space? This doesnt seem to work becuase it doesn’t stop on the first space it takes all the spaces there are ;P
str = str.replace(/\|(.*?) /gs, '');


