Jump to content

Need Assistance with Regex


Yahweh

Recommended Posts

I couldn't find a more appropriate place to put this thread, but no worries :)I'm writing a small BBCode engine for my website, and I haven't had any trouble with it until now. I've been trying to figure out how to make regex ignore matches if they contain a certain word. Example:

Source text:----------[color=red]This color is red[/color][color=white]This bunny is white[/color][color=blue]This is blue[/color][color=green]Bunnies are adorable[/color]Regex:----------\[color=(?:\s{0,})([^\];]+)\]([\S\s]*?)\[\/color\]Results:----------Match                                    $1      $2 [color=red]This color is red[/color]     red     This color is red [color=white]This bunny is white[/color] white   This bunny is white [color=blue]This is blue[/color]         blue    This is blue[color=green]Bunnies are adorable[/color] green  Bunnies are adorable

However, I want to exclude matches where $2 contains "bunny" or "bunnies" anywhere in the text. Here is the desired input and output:

Source text:----------[color=red]This color is red[/color][color=white]This bunny is white[/color][color=blue]This is blue[/color][color=green]Bunnies are adorable[/color]Regex:----------***Haven't figured out this step yet***Results:----------Match                                   $1      $2 [color=red]This color is red[/color]     red     This color is red[color=blue]This is blue[/color]         blue     This is blue

I've been working on this for a while, and it should be incredibly simple but I haven't figured it out yet. What regex code would I need to use to get my desired matches?Note: you can test your regex patterns here:http://regexlib.com/RETester.aspx

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...