LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2011, 08:37 PM   #1
lesca
Member
 
Registered: Sep 2010
Posts: 58

Rep: Reputation: 0
Smile Regex: word^ matches what?


This regular expression may be the key, when I try to understand
Code:
sudo apt-get install lamp-server^
The manual says
Quote:
... anchor the regular expression with a '^' or '$' character, or create a more specific regular expression.
But there is no example how it works.

Any tip is welcome! Thanks!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-05-2011, 01:09 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well ^ means that *start* of the line, and $ means the end. so it'd be ^lamp-server to match strings starting with that phrase. I've never seen regexes used with apt-get though, is that supposed to work?
 
Old 02-05-2011, 05:23 PM   #3
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
@acid_kewpie, from the man-page:
Quote:
If no package matches the given expression and the expression contains one of '.', '?' or '*' then it is assumed to be a POSIX regular expression, and it is applied to all package names in the database. Any matches are then installed (or removed). Note that matching is done by substring so 'lo.*' matches 'how-lo' and 'lowest'. If this is undesired, anchor the regular expression with a '^' or '$' character, or create a more specific regular expression.
@lesca:
You might be interested in some basic regular expression stuff - they're quite useful this is, as the link's title says, a very brief introduction to them...
 
Old 02-06-2011, 02:26 AM   #4
lesca
Member
 
Registered: Sep 2010
Posts: 58

Original Poster
Rep: Reputation: 0
But I think "^" should be at the start of the expression. Why not?
 
Old 02-06-2011, 02:49 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Expression matching can be whatever Humpty Dumpty chooses it to mean.
Don't confuse it with regex - whatever that means ...
 
Old 02-06-2011, 08:34 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by lesca View Post
But I think "^" should be at the start of the expression. Why not?
Who said it shouldn't?

The apt-get man page assumes you are familiar with regular expressions, and if you were, you would know what ^ and $ mean.

^ means the beginning of the string, $ means the end.

For example, the regex "es" will match the word "test", but "^es" will not, because the string doesn't start with "es".
 
Old 02-06-2011, 11:03 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by lesca View Post
Code:
sudo apt-get install lamp-server^
I suppose better questions might be where did you see this and how do you know it's not an error? It sounds like apt-get uses "inspired by" POSIX regular expressions. It certainly wouldn't match anything as an extended POSIX regular expression; as a non-extended regular expression "^" is interpreted literally, but I doubt "^" is part of a normal package name.
Kevin Barry

Last edited by ta0kira; 02-06-2011 at 11:07 PM.
 
Old 02-07-2011, 02:18 AM   #8
lesca
Member
 
Registered: Sep 2010
Posts: 58

Original Poster
Rep: Reputation: 0
Thank you for your answer.
I am sure it's right, because I followed those steps here
 
Old 02-07-2011, 04:16 AM   #9
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
According to this page
https://help.ubuntu.com/community/Tasksel
the '^' makes
sudo apt-get install lamp-server^
behave as an alternative to
sudo tasksel install lamp-server
 
2 members found this post helpful.
Old 02-07-2011, 03:29 PM   #10
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by ta0kira View Post
It sounds like apt-get uses "inspired by" POSIX regular expressions.
I dunno, the man-pages said it was treated as a POSIX regular expression. Did you have a particular reason to believe it doesn't behave the same way?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash replace all matches of regex substring in string nickleus Linux - General 3 04-30-2011 11:08 AM
[SOLVED] awk ordering of regex matches dazdaz Programming 12 11-06-2010 02:08 AM
REGEX from array, returns no matches. dr_strangelove Linux - Server 2 06-23-2010 06:30 PM
grep regex . matches new lines?! lambchops468 Linux - Newbie 3 03-24-2008 09:19 PM
Regex Question: Only print part of line that matches TheMeteorPolice Programming 5 01-12-2006 01:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration