Make text between asterisks bold
A simple regex will do the trick:
$thenewtext = preg_replace('#\*{2}(.*?)\*{2}#', '<b>$1</b>', '**Hello World** of PHP');
Wrap text between two asterisks in HTML *bold*
This seems to work pretty well:
var str = "This is my string and *this text* should be wrapped with";
var updatedstr = String.Concat(
Regex.Split(str, @"\*")
.Select((p, i) => i % 2 == 0 ? p :
string.Concat("<strong>", p, "</strong>"))
.ToArray()
);
Markdown to convert double asterisks to bold text in javascript
Your regex is broken, for one thing. You probably want something more like:
/\*\*[A-z0-9]+\*\*/gi
The *
is a special character in regular expressions. If you want to match against a literal *
, then you need to escape it with \
.
For instance: http://jsfiddle.net/2LAL4/22/
However, even with this change there's still a fair ways to go before you get to where you really want to be. For instance, your example will not work if the text area contains a mix of bold and non-bold text.
Related Topics
How to Get Column Names from Pdo's Fetchall Result
How to Fetch Data in PHP with MySQLi
Using Seo User Friendly in PHP
Google+ Login via JavaScript and PHP
Simple PHP Mail Function Not Working on Amazon Server Ec2
How to Get a PHP Value from an HTML Form
Saving Div Contents or Canvas as Image
Get the Selected Index Value of <Select> Tag in PHP
Php: "Short_Open_Tag = On" Not Working
How to Integrate PHPmailer with Codeigniter 3
Mysql: Determine Table's Primary Key Dynamically
Regex for Dropping Http:// and Www. from Urls
How to Disable PHP Magic Quotes at Runtime
Pdo Cannot Execute Queries While Other Unbuffered Queries Are Active
Displaying Blob Image from MySQL Database into Dynamic Div in HTML