- first character in a line or after a space is the formatting character
- all characters between formatting characters are not spaces
- last character in a line or before a space is the formatting character
*this*is*bolded* = this is bolded
/italics/ = italics
_and_underlined_ = and underlined
Examples when not to format:
http://website.tld/ = http://website.tld/
some_file_name.ext = some_file_name.ext
this*is*not*bold = this*is*not*bold
I can't seem to figure out how to catch the start and end of a line. I assumed that I could use this regex:
Code: Select all
~([\s\b])([\*\/\_])((?:[^\s]+?\2)+)([\s\b])~([\s\b]) matches a whitespace character or a word break and saves it as \1
([\*\/\_]) matches an asterisk, a forward slash, or an underscore and saves it as \2
((?:[^\s]+?\2)+) matches multiple occurrences of non-whitespace characters followed by the content of \2 and saves it as \3
([\s\b]) matches a whitespace character or a word break and saves it as \4
If there is a space both before and after the formatted content, this works. However, this is oftentimes not the case, as paragraphs may start with a formatted word or sentences may end with a formatted word, followed by a period. It also seems that using \b doesn't help at all. Does anyone know how to accomplish this?