Skip to contentSkip to conversation

Regular Expression Problem

DISCUSSION Park Lee 3 participants 3 messages Jun 12, 2004 SELinux security module

lore
Share & tools
lore

Park Lee

author
#0 lore raw

Hi,

In the file_contexts file, I found some regular expressions. I studied them for a while, but still can't understand them well.

For example: /var(/.*)

As I know: '.' stands for any character;
Let's suppose '.' now stands for character 'a'.
then '/var(/.*)' can mean:
'/var/a','/var/aa','/var/aaa','/var/aaaa','/var/aaaaa', ... ...

But now, If I have a file or directory named 'abc' in directory '/var' (i.e., /var/abc). How can it match '/var(/.*)' ?

Thank you.

Park Lee

---------------------------------
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger

#1 lore raw
Quoted 6 lines · Park Lee

Hi,

In the file_contexts file, I found some regular expressions. I studied them for a while, but still can't understand them well.

For example: /var(/.*)

Quoted 7 lines

As I know: '.' stands for any character;
Let's suppose '.' now stands for character 'a'.
then '/var(/.*)' can mean:
'/var/a','/var/aa','/var/aaa','/var/aaaa','/var/aaaaa', ... ...

But now, If I have a file or directory named 'abc' in directory '/var' (i.e., /var/abc). How can it match '/var(/.*)' ?

well, i don't pretend to understand regular expressions either:
they are one of the most obscure nasty amazingly compact hang-overs from the days when computers didn't have enough space to store wordey programs or programming languages.

i think you'll find that the regular expression you are referring to is "/var(/.*)?" note the question mark which means it's optional.

dot means any one character, and star means zero or more characters.

so dot star means "one or more characters".

obtuse as it is, can i recommend that you read up on several sources of regular expressions, for example "man regex" and also

http://www.google.com/search?q=regular+expressions

remember we said google is your friend? well we REALLY MEANT IT!

if you don't know about something, put some random words into google, first.

THEN if you can't find an answer, and it's definitely SE/Linux related, ask.

sincerely,

l.

Signature · 14 lines
-- 
Information I post is with honesty, integrity, and the expectation that
you will take full responsibility for acting on the information contained,
and that, should you find it to be flawed or even mildly useful, you
will act with both honesty and integrity in return - and tell me.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:[email protected]"> [email protected] </a> <br />


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
In reply to Park Lee
Quoted 4 lines · Park Lee

As I know: '.' stands for any character;
Let's suppose '.' now stands for character 'a'.
then '/var(/.*)' can mean:
'/var/a','/var/aa','/var/aaa','/var/aaaa','/var/aaaaa', ... ...

The '*' is evaluated before the '.'. So /var(/.*) expands to '/var/.', '/var/..', '/var/...', and then in each case the '.' characters are expanded independently.

See regex(7) for all the details.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.