Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to debug a regex with (?DEFINE)?

Thread Tools

How to debug a regex with (?DEFINE)?

Peng Yu
Posts: n/a

I'm trying to extract the nested namespace in the following code. But
the code can only extract the inner namespace. It is very hard for me
to see what is wrong. Does anybody know some tricks how to debug a
regex like the following? Thanks!

~/linux/test/perl/man/perlre/(?/(/DEFINE$ cat
#!/usr/bin/env perl

use strict;
use warnings;

my $text=<<'EOF';
namespace A {
namespace B {

# Build pattern that matches only namespaces...
my $namespace_pattern = qr{
((?&namespace)) # Match and capture (possibly nested)

# Define each component...
\b [A-Za-z_]\w* \b

\b namespace \b

# Namespace is keyword + name + block...
(?&namespace_keyword) \s+ (?&namespace_token) \s*


(?: (?&block) | . )*?

my ($extracted) = $text =~ $namespace_pattern;

print "text = $text\n";
print "extracted = $extracted\n";

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How make regex that means "contains regex#1 but NOT regex#2" ?? Python 3 07-01-2008 03:06 PM
Config Mgr Debug/Release and Web.config Compilation debug=true RonL ASP .Net 0 04-08-2006 03:50 PM
Debug (DLL MFC) -> Debug (Static MFC) ringos75 C++ 0 04-14-2005 01:50 PM
[Howto] Compiling debug Python extensions for non-debug Python Mike C. Fletcher Python 3 10-12-2003 09:37 PM