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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
09-19-2006, 12:28 PM
|
#1
|
Member
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194
Rep:
|
Don't match a regular expression
I haven't been able to find this but it must be simple enough ...
Given a regular expression that identifies a text pattern and produces a set of results, how do I change the expression so that it that gives me the complement of that set, i.e. all the lines in the file that do not match my regexp?
|
|
|
09-19-2006, 12:40 PM
|
#2
|
Member
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172
Rep:
|
From man grep:
Quote:
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
|
|
|
|
09-19-2006, 12:47 PM
|
#3
|
Member
Registered: Sep 2005
Distribution: LFS
Posts: 60
Rep:
|
It would depend on what you are using to process the expression. If you are using grep use the -v (--invert-match) switch. If you are using perl, I believe you can use the !~= operator.
Thanks,
Mark
Last edited by mjones490; 09-19-2006 at 01:37 PM.
|
|
|
09-19-2006, 04:09 PM
|
#4
|
Member
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194
Original Poster
Rep:
|
I am actually doing this in BBEdit, which supports regular expressions, hence wondering if this can be done with a single expression. I guess that Grep is probably the easiest option, from which I can just divert the output to one of the internal buffers (or whatever they call them...) but I will try perl syntax first ... edit: no luck
Thanks.
Last edited by dakensta; 09-19-2006 at 04:13 PM.
|
|
|
09-20-2006, 02:09 AM
|
#5
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,405
|
Perl is
!~
for not match,
=~
for does match
Note that regex engines inside various tools eg bash/awk/grep/perl etc etc are not all the same. See http://www.oreilly.com/catalog/regex/
|
|
|
09-20-2006, 04:47 AM
|
#6
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
Usually a ^ will take care of negation
Code:
if(!(ereg("[A-Z]",$data['password']) &&
ereg("[a-z]",$data['password']) &&
ereg("[0-9]",$data['password']) &&
ereg("[^A-Za-z0-9]",$data['password'])))
The last line in this piece of PHP code checks for something not being A-Z,a-z or 0-9 (so matching anything else). This is pure regexp and independent of programming languages or tools.
So your regexp should be like to find i.e. any punctuation, braces etc.
|
|
|
09-21-2006, 03:57 AM
|
#7
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,405
|
|
|
|
09-21-2006, 04:48 AM
|
#8
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
Hi Chrism01,
sorry, but I don't see the warning. Can you quote part (or all) of it please so I can find it.
PS only find posts from jason denying a possible broken implementation
|
|
|
All times are GMT -5. The time now is 05:49 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|