# Regex help?

**URL:** <https://forum.kirupa.com/t/regex-help/286671>\
**Category:** programming\
**Created:** [April 18, 2009, 9:45pm UTC](https://forum.kirupa.com/t/regex-help/286671 "2009-04-18T21:45:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorren\_biffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/lorren_biffin/32/2726_2.png) [@lorren\_biffin](https://forum.kirupa.com/u/lorren_biffin)\
**Post date:** [April 18, 2009, 9:45pm UTC](https://forum.kirupa.com/t/regex-help/286671/1 "2009-04-18T21:45:45Z")

</div>

Hey all,

I’m in the process of learning Regex, and trying to put together a real-world example… Here’s my problem:

I need to format strings that have _phrases like this_, and phrases /like this/, where strings surrounded by asterisks would be wrapped with \<strong\> tags, and strings surrounded by forward-slashes would be wrapped with \<em\> tags. These strings can contain HTML tags. When formatting the strings, the formatting marks (\* and /) should be replaced by their relative tags. Here are my current expressions:

```auto

Strong Exp: /\s+[*]+([^*]+)[*]+\s+/i
Em Exp: /\s+[\/]+([^\/]+)[\/]+\s+/i

```

Obviously, these are not sufficient for my needs… The primary reasons being that I need to:  
[LIST=1]  
[_]Ignore instances where the string begins and/or ends inside of an HTML tag, and  
[_]Ignore instances where the formatting marks are part of larger strings where those marks are necessary such as in a URL (http:\*\*//\*\*[google.com](http://google.com)) or while in a notation (…\*\*\*\*\*Offer valid only on in-store…)  
[/LIST]

An example string:

```auto
*know who, http://dude.com .. *that's* right, /bro/!

```

Where-as the word “that’s” would be bold, and the word “bro” would be italic.

I’m at a loss. Any ideas?

Thanks in advance! 😃
