Inverse Sequence Matching

B

bilaribilari

Hello,
I have the following text:

<SP>http://poplet.com/laseaer<SP><SP>some:text with colon<SP>

I am trying to come up with a regular expression that
1. Matches anything between <SP> tags, and
2. Does NOT match if the text contains ://

I.e. the regex should match 'some:text with colon' but NOT the url.

I have tried a lot of possiblities, but am not able to get the result I
require. Please help me crack this one. It must be pretty trivial for
many people.

Thanks in advance.

Best regards,
B.
 
D

David Squire

Hello,
I have the following text:

<SP>http://poplet.com/laseaer<SP><SP>some:text with colon<SP>

I am trying to come up with a regular expression that
1. Matches anything between <SP> tags, and
2. Does NOT match if the text contains ://

I.e. the regex should match 'some:text with colon' but NOT the url.

Hmmm. This does not look like a very stable mark-up, unless there are
constraints you have not mentioned. The code below seems to do what you
want, but see the caveats embedded in the example.

----

#!/usr/bin/perl
use strict;
use warnings;

while (<DATA>) {
my @Matches = m{<SP>(?!http://|<SP>)(.*?)<SP>}g;
print "$_\n" for @Matches;
}

__DATA__
<SP>http://poplet.com/laseaer<SP><SP>some:text with colon<SP>
what if there is leading
text?<SP>http://poplet.com/laseaer<SP><SP>some:text with colon<SP>
<SP>Are the beginning and end <SP> tags really
identical?<SP><SP><SP><SP>I can imagine that causing problems http://<SP>

----

Output:

some:text with colon
some:text with colon
Are the beginning and end


Regards,

DS
 
T

Tad McClellan

I have the following text:

<SP>http://poplet.com/laseaer<SP><SP>some:text with colon<SP>

I am trying to come up with a regular expression that
1. Matches anything between <SP> tags, and
2. Does NOT match if the text contains ://


my @matches = grep !m#://#, /<SP>(.*?)(?=<SP>)/g;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top