Thread View: news.software.readers
7 messages
7 total messages
Started by Lars Stokholm
Fri, 30 Apr 2004 20:25
[slrn] RegEx matching a Message-ID
Author: Lars Stokholm
Date: Fri, 30 Apr 2004 20:25
Date: Fri, 30 Apr 2004 20:25
10 lines
1372 bytes
1372 bytes
I'm trying to write a regular expression to be used in a macro, that will match a Message-ID, but I'm not having much luck. I'm really having trouble escaping characters with backslash (I can't even escape a single dot). So I have two questions for you: 1) Can you come up with anything better than this(?): news:[^ >]+ You probably can. :) 2) How do I escape a ')' in S-Lang? This won't work: string_match(article,"news:[^ >\)]+",1);
Re: [slrn] RegEx matching a Message-ID
Author: Dirk Nimmich
Date: Fri, 30 Apr 2004 20:39
Date: Fri, 30 Apr 2004 20:39
9 lines
1248 bytes
1248 bytes
Lars Stokholm wrote: > 1) Can you come up with anything better than this(?): news:[^ >]+ Tin uses \b(?:s?news|nntp):[^\s@]+[@.][^\s@]+(?:$|(?=[\s.><,\"/():]))\b (PCRE style).
Re: [slrn] RegEx matching a Message-ID
Author: Lars Stokholm
Date: Fri, 30 Apr 2004 20:58
Date: Fri, 30 Apr 2004 20:58
6 lines
1242 bytes
1242 bytes
Dirk Nimmich wrote: > \b(?:s?news|nntp):[^\s@]+[@.][^\s@]+(?:$|(?=[\s.><,\"/():]))\b Thank you, but it seems very different from what S-Lang recognizes: http://space.mit.edu/~davis/slang/doc/html/slang-18.html
Re: [slrn] RegEx matching a Message-ID
Author: J.B. Nicholson-Owens
Date: Sat, 01 May 2004 00:28
Date: Sat, 01 May 2004 00:28
29 lines
2403 bytes
2403 bytes
Dirk Nimmich wrote:
> Tin uses
>
> \b(?:s?news|nntp):[^\s@]+[@.][^\s@]+(?:$|(?=[\s.><,\"/():]))\b
If you can't wait for PCRE to be used in S-Lang, try the following:
if (andelse
{ orelse { string_match (m, "^nntp:", 1) } { string_match (m, "^s?news:", 1) } }
{ string_match (m, ":[^@]+@", 1) }
{ string_match (m, "@[-a-zA-Z0-9.]+",1 ) })
{ ... it matched ... }
where 'm' is a word that might be a message-ID.
The above code snippet is not the same as above the PCRE expression; coding
all the fancy things one can do with a modern regular expression engine in a
snippet brief enough to share here is not trivial. Regular expressions are
a far better method of doing this job. But this might give you a good
starting place or some inspiration to get something good enough for testing
or playing with.
In the future if PCRE became the regular expression engine of the next major
S-Lang, you should be able to use the same expression tin uses or a better
one. If you wish, you can check out
ftp://space.mit.edu/pub/davis/misc/modules-1.4.8.tar.gz which has a PCRE
module. Please do tell people if your macros require a specific module so
they can load that module into their S-Lang-based program before
interpreting your macro.
Re: [slrn] RegEx matching a Message-ID
Author: Lars Stokholm
Date: Sat, 01 May 2004 06:22
Date: Sat, 01 May 2004 06:22
20 lines
1901 bytes
1901 bytes
J.B. Nicholson-Owens wrote:
> if (andelse
> { orelse { string_match (m, "^nntp:", 1) } { string_match (m, "^s?news:", 1) } }
> { string_match (m, ":[^@]+@", 1) }
> { string_match (m, "@[-a-zA-Z0-9.]+",1 ) })
> { ... it matched ... }
In fact I want to search the entire article for a Message-ID, with
'string_match', and use 'string_match_nth' afterwards to get the exact
position and length of that. The code above will only tell me that
there is a Message-ID, right? - Not the exact location in the string?
But thanks anyway, you couldn't have guessed what I wanted. :)
What would I do if I wanted to match any string that didn't contain
a ']'? Normally I would just use this, I guess: [\]]*
> If you wish, you can check out [...]
I guess I would have to recompile slrn with that module, right?
Re: [slrn] RegEx matching a Message-ID
Author: Lars Stokholm
Date: Sat, 01 May 2004 06:34
Date: Sat, 01 May 2004 06:34
5 lines
1160 bytes
1160 bytes
J.B. Nicholson-Owens wrote: > [-a-zA-Z0-9.]+ Won't that match any nonempty string? Shouldn't the period be escaped?
Re: [slrn] RegEx matching a Message-ID
Author: Lars Stokholm
Date: Sat, 01 May 2004 12:47
Date: Sat, 01 May 2004 12:47
10 lines
1431 bytes
1431 bytes
Lars Stokholm wrote: > Won't that match any nonempty string? Shouldn't the period be escaped? I guess not. :) This seems to be OK: news:[-a-zA-Z0-9$.]+@[-a-zA-Z0-9.]+ Here is the rest of the macro, if anyone wants to criticise: http://home19.inet.tele.dk/stokholm/slrn/newslinks.sl
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads