in reply to Must use regex, how to clip...

This is a perl question, right? (I mean, you are actually using perl to run your regex over the data, aren't you?) If not, then I'm sorry I misunderstood...

Anyway, are you sure you can't use "index()", "rindex()" and "substr()" instead of regexes? (I guess "length()" could be helpful, too.) E.g.:

$bgn_target = "<!--begin node-->"; $bgn_offset = index( $_, $bgn_target ) + length( $bgn_target ); $keep_length = rindex( $_, "<!--end node-->" ) - $bgn_offset; $keep_string = substr( $_, $bgn_offset, $keep_length );
Okay, it's a bit clumsy, and could be done more compactly, but it's one way of doing the job, if it's available to you.

update: Looking at your post again, I figure the above suggestion is totally off the mark -- oh well.

Getting back to the regex... it may be that you don't need to worry at all about the stuff that precedes the first "begin node" signal -- just this much ought to match what you want to retain:

/<!--begin node-->(.*)<!--end node-->/
(that is, assuming that your regex engine -- whatever it is -- knows about using parens to capture part of a match)

When you say you can't "supply any options", does this mean you can't use use the "s" qualifier on the match (so that "." matches new-lines as well as all other characters)? Or is this not an issue for you?

(The whole setup as you describe it seems kinda cryptic and warped, like your working inside a totalitarian regime...)

Replies are listed 'Best First'.
Re: Re: Must use regex, how to clip...
by chantstophacking (Acolyte) on Jan 11, 2003 at 00:39 UTC
    This is a perl question, right? (I mean, you are actually using perl to run your regex over the data, aren't you?)

    ...well it is a Perl question in this sense. I have a content management system (TWiki) and it is implemented in Perl. It allows a convention for syndicating other content through the use of a regex. I presume it is simply taking the argument I pass to it (through an %INCLUDE{} directive) and applying it to the incoming HTML stream.

    So I am not using the m// operator directly. I'm simply passing a regex, and I presume that the system puts my regex into the match operator for me.

    The whole thing is incompletely documented, so I have to make some guesses about how it's working.

    (The whole setup as you describe it seems kinda cryptic and warped, like your working inside a totalitarian regime...)

    in a way, that's true. But I'm only prevented from understanding it more fully by the fact that I'm too lazy to dig through the code right now to see what they're doing to my regex. I know that a new version is coming out any day, and I don't want to patch something that may be totally different in the next release. (On the other hand, if I solve this problem from the user level, that solution may need to change at the next rev anyway.) But I sort of hoped that maybe I'd find a clever way to write a Perl regex that solves my problem.