Gentoo Archives: gentoo-user

From: tecnic5@××××××××.com
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Regex question
Date: Wed, 04 Jun 2008 06:57:22
Message-Id: OF9A648F46.A22B1EB0-ONC125745E.0025B48D-C125745E.00262FE4@com
In Reply to: Re: [gentoo-user] Regex question by Iain Buchanan
1 Hi,
2
3 I just wanted to comment something about Iain's suggestion:
4
5 '^\?.*(http|https|ftp)://'
6
7 If you add that '^' you're assuming that's the beginning of the string (as
8 you may already know); the thing is I cannot see the cases where your URL
9 starts with '?', the characters, and finally protocol and rest of URL. I
10 mean, I can understand you found that string somewhere in the URL, but I
11 don't see it being like that from the very beginning.
12
13 Perhaps I missed something by the way, can you guys enlight me?
14
15 Regards,
16
17 Abraham Marín Pérez <tecnic5@××××××××.com>
18 Responsable de I+D
19 SILVANO CONSULTORES
20 Tfno.: 93.412.79.12 -- Fax: 93.410.92.90
21 http://www.silvanoc.com/
22
23
24
25
26
27
28 Iain Buchanan <iaindb@××××××××××××.au>
29 04/06/2008 01:33
30 Por favor, responda a gentoo-user
31
32 Para: gentoo-user@l.g.o
33 cc:
34 Asunto: Re: [gentoo-user] Regex question
35
36 Hi,
37
38 On Tue, 2008-06-03 at 17:39 +1000, Adam Carter wrote:
39 > I want to filter the strings; ? <something> http:// or ? <something?
40 > https:// or ? <something> ftp:// from URLs in apache. I know i need to
41 > escape ? but i'm not sure about /
42
43 / needs to be escaped in perl if your regex delimiters are / as well,
44 but here you use ' so I would _hope_ that you don't need \/\/ sort of
45 syntax. YMMV.
46
47 > and i've used '(something|otherthing|whatever)' to make the 'or's
48 > work.
49
50 I usually do perl, but it should be the same... Actually on reading
51 further, "Apache uses Perl Compatible Regular Expressions provided by
52 the PCRE library." Neat. You should be viewing this with a fixed width
53 font too :)
54
55 > <LocationMatch '(\?.*http:\/\/|\?.*https:\/\/|\?.*ftp"\/\/)'>
56 typo here==============================================^
57
58 how about taking the common bits out of the ()
59 '\?.*(http|https|ftp)://'
60
61 and it's good practise to use ^ if that's what you're expecting:
62 '^\?.*(http|https|ftp)://'
63
64 > Order allow,deny
65 > Deny from all
66 > </LocationMatch>
67 >
68 > is that regex correct? Will egrep use the exact same regex syntax (so
69 > i can use it to check?)
70
71 I think they're essentially the same, with the exception of some classes
72 (like [:punct:] or [\d]). egrep may need some extra escaping so as not
73 to confuse your shell. The best way to test is to use the real program,
74 so see if you can get info out of your logs to help.
75
76 hth,
77 --
78 Iain Buchanan <iaindb at netspace dot net dot au>
79
80 I tripped over a hole that was sticking up out of the ground.
81
82 --
83 gentoo-user@l.g.o mailing list
84
85
86
87 --
88 gentoo-user@l.g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Regex question Iain Buchanan <iaindb@××××××××××××.au>