Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion regexp: parsing HTML tokens
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Donal K. Fellows  
View profile  
 More options May 17 2005, 6:54 am
Newsgroups: comp.lang.tcl
From: "Donal K. Fellows" <donal.k.fell...@manchester.ac.uk>
Date: Tue, 17 May 2005 11:54:55 +0100
Local: Tues, May 17 2005 6:54 am
Subject: Re: regexp: parsing HTML tokens

aren...@comcast.net wrote:
> regexp -nocase {(\<\%\@ page) (\%\>)} $string result
> -> 0

You're probably after this:

   regexp -nocase {<%@\s*page\s*((?:(?!%>).)*)%>} $string \
          wholeMatch interestingContent

How does it work? Simple. Firstly, none of <%@> are special chars to RE
by themselves. Secondly, the first part (up to the second \s*) matches
the start of the interesting chunk from your string, and there's a
literal %> at the end. Thirdly, there's a bunch of real RE magic in the
middle:
   ((?:(?!%>).)*)

Looking at that in detail, we see this in expanded form

   (              # Stash this sub-RE in a variable
    (?:           # Pure grouping of zero-width assertion and matcher
      (?! %> ) .  # any character, as long as it isn't the start of %>
    ) *           # and as many of them as possible
   )              # That's All Folks!

The key to doing sane parsing is often the negative lookahead assertion.
It makes life *so* much easier!

Donal.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.