FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 10-04-2011, 10:12 PM
T Elcor
 
Default OT: Javascript regex Q

Hi,

Is there a way to write a single Javascript regex that would match all of the following three patterns:

a.domain.tld
b.domain.tld
domain.tld/c/

Thanks


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1317766378.87936.YahooMailClassic@web121918.mail.n e1.yahoo.com">http://lists.debian.org/1317766378.87936.YahooMailClassic@web121918.mail.n e1.yahoo.com
 
Old 10-05-2011, 10:52 AM
Darac Marjal
 
Default OT: Javascript regex Q

On Tue, Oct 04, 2011 at 03:12:58PM -0700, T Elcor wrote:
> Hi,
>
> Is there a way to write a single Javascript regex that would match all of the following three patterns:
>
> a.domain.tld
> b.domain.tld
> domain.tld/c/

/.*/

Or, perhaps you're after /domain.tld/

Either should work, though I'd expect the first to be quicker in your
case.



--
Darac Marjal


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20111005105252.GB21600@darac.org.uk">http://lists.debian.org/20111005105252.GB21600@darac.org.uk
 
Old 10-05-2011, 01:06 PM
T Elcor
 
Default OT: Javascript regex Q

--- On Wed, 10/5/11, Darac Marjal <mailinglist@darac.org.uk> wrote:

> >
> > Is there a way to write a single Javascript regex that
> would match all of the following three patterns:
> >
> >***a.domain.tld
> >***b.domain.tld
> >* ***domain.tld/c/
> >
>
>
> /.*/
>
> Or, perhaps you're after /domain.tld/
>
> Either should work, though I'd expect the first to be
> quicker in your case.

No, this isn't what I'm looking for. I'm not after blocking everything or the whole domain.tld, only the three above URI patterns.

I came across this trying to rewrite my ad blocking list in a more elegant way, but couldn't see any obvious way to make it with one regex without blocking more than necessary.

Thanks


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1317819992.65138.YahooMailClassic@web121909.mail.n e1.yahoo.com">http://lists.debian.org/1317819992.65138.YahooMailClassic@web121909.mail.n e1.yahoo.com
 
Old 10-05-2011, 01:17 PM
Eduardo M KALINOWSKI
 
Default OT: Javascript regex Q

On 10/05/2011 10:06 AM, T Elcor wrote:
> --- On Wed, 10/5/11, Darac Marjal <mailinglist@darac.org.uk> wrote:
>
>>> Is there a way to write a single Javascript regex that
>> would match all of the following three patterns:
>>> a.domain.tld
>>> b.domain.tld
>>> domain.tld/c/
>>>
>>
>> /.*/
>>
>> Or, perhaps you're after /domain.tld/
>>
>> Either should work, though I'd expect the first to be
>> quicker in your case.
> No, this isn't what I'm looking for. I'm not after blocking everything or the whole domain.tld, only the three above URI patterns.
>
> I came across this trying to rewrite my ad blocking list in a more elegant way, but couldn't see any obvious way to make it with one regex without blocking more than necessary.

Well, you didn't say you wanted _only_ that to match.

^(a.)?domain.tld(/c/)?$

JavaScript syntax might be slightly different, but that's the idea.


--
All generalisations are dangerous, including this one.

Eduardo M KALINOWSKI
eduardo@kalinowski.com.br


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E8C58DC.7020103@kalinowski.com.br">http://lists.debian.org/4E8C58DC.7020103@kalinowski.com.br
 
Old 10-05-2011, 01:39 PM
T Elcor
 
Default OT: Javascript regex Q

--- On Wed, 10/5/11, Eduardo M KALINOWSKI <eduardo@kalinowski.com.br> wrote:
>
> ^(a.)?domain.tld(/c/)?$
>
> JavaScript syntax might be slightly different, but that's
> the idea.

I had similar idea
(a.|b.|)domain.tld(|/c/)
but just like your regex it would block the whole domain.tld as well, which isn't what I want.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1317821979.49949.YahooMailClassic@web121912.mail.n e1.yahoo.com">http://lists.debian.org/1317821979.49949.YahooMailClassic@web121912.mail.n e1.yahoo.com
 
Old 10-05-2011, 01:55 PM
Eduardo M KALINOWSKI
 
Default OT: Javascript regex Q

On 10/05/2011 10:39 AM, T Elcor wrote:
> I had similar idea
> (a.|b.|)domain.tld(|/c/)
> but just like your regex it would block the whole domain.tld as well, which isn't what I want.

I overlooked that.

Well, ([ab].domain.tld)|(domain.tld/c/)

should work and is one regexp, but it is ugly. I'd use two separate
ones, one for matching things at the beginning and one for things at the
end.

--
FORTUNE PROVIDES QUESTIONS FOR THE GREAT ANSWERS: #21
A: Dr. Livingston I. Presume.
Q: What's Dr. Presume's full name?

Eduardo M KALINOWSKI
eduardo@kalinowski.com.br


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E8C61BC.9010108@kalinowski.com.br">http://lists.debian.org/4E8C61BC.9010108@kalinowski.com.br
 
Old 10-05-2011, 02:00 PM
Tom Furie
 
Default OT: Javascript regex Q

On Tue, Oct 04, 2011 at 03:12:58PM -0700, T Elcor wrote:

> Is there a way to write a single Javascript regex that would match all of the following three patterns:
>
> a.domain.tld
> b.domain.tld
> domain.tld/c/

You could try /^[ab].domain.tld$|^domain.tld/c/$/. If you don't
mind also matching a.domain.tld/c/ and b.domain.tld/c/ then
/^(?:[ab].)?domain.tld(?:/c/)?$/ might work.

These are untested as I don't do javascript but cobbled them together
from a quick look at the table on
https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions

Cheers,
Tom

--
LOAD "LINUX",8,1
-- Topic on #LinuxGER
 
Old 10-05-2011, 02:30 PM
T Elcor
 
Default OT: Javascript regex Q

--- On Wed, 10/5/11, Eduardo M KALINOWSKI <eduardo@kalinowski.com.br> wrote:

> Well, ([ab].domain.tld)|(domain.tld/c/)
>
> should work and is one regexp, but it is ugly.

Yeah, that should work but I was hoping there'd be a more elegant way of doing that.

> I'd use two separate ones

That's what I'm doing now.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1317825025.91220.YahooMailClassic@web121902.mail.n e1.yahoo.com">http://lists.debian.org/1317825025.91220.YahooMailClassic@web121902.mail.n e1.yahoo.com
 

Thread Tools




All times are GMT. The time now is 08:39 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org