RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(?<!\\)\[(\\\[|\\\]|[^\[\]]|(?<!\\)\[.*(?<!\\)\])*(?<!\\)\]
Description
This regular expression will find the highest level groups within recursive tokens. For instance, if I have &quot;This is [just [an] example] of the [expression]&quot;, it'll find [just [an] example] and [expression], and nothing else. It will also not find an escaped bracket expression. If you want to replace the bracket with curly braces or parenthesis, be careful. As an example, curly braces will be: (?&lt;!\\)\{(\\\{|\\\}|[^\{\}]|(?&lt;!\\)\{.*(?&lt;!\\)\})*(?&lt;!\\)\}
Matches
[just] | [just [an] example]
Non-Matches
\[just]
Author Rating: The rating for this expression. Joaquin Jares
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Actually, it's only one level
Name: Joaquin Jares
Date: 7/21/2005 1:13:23 PM
Comment:
I may have stated it incorrectly. This regex will only find the highest level groups. Then I can recurse into them manually. What it does is ignore included groups, which is just what I needed.


Title: Not recursive. Just two levels.
Name: Randal L. Schwartz
Date: 7/21/2005 12:26:20 PM
Comment:
It's not possible using a single regular expression to find arbitrarily nested matching character pairs. Read the literature... this is stated time and time again. Your regex finds only two levels of nested pairs.


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials