Re: regex, negations, grep, find and replace (a few questions)
- From: pk <pk@xxxxx>
- Date: Mon, 26 Nov 2007 17:07:32 +0100
jameshanley39@xxxxxxxxxxx wrote:
I heard that it is hard to negate a regex.No where near enough information.
well, if one/I/"you" wanted to match NOT "hello world" , using a regex.
I do not know much regex. But it seems as if you define each character
individually. Except with * which defines many, and since . means any,
so .* defines a string of any.
There is much more than that to regexps. Also, be aware that different tools may use slightly different syntaxes for the same regular expressions.
Imho, the most powerful regular expressions are those used by perl.
it seems like you can only negate characters. or many of certain
characters.
[cut] Apparently it is hard, and ugly too, moreso for a long string, to say
NOT (h followed by e, .....)
Note that (depending on the context) "matching the negation of a regular expresion" might mean "matching everything not matching the regular expression" or, in other words, removing everything matching the regexp. So, you might simply use sed to remove all the occurrences of the pattern in the text, leaving everything not matching the regexp in place, eg
$ sed -e 's/pattern//g' your_file
note- i have a program called regex coach in windows. If you heard of
it, do you know of a linux equivalent, or more appropriate linux
program? It shows you if a regex pattern matches some target string,
and updates itself each time you enter a new character into the regex
pattern or target string. It highlights the match(es).
There are plenty. You might want to investigate, for example, regexxer, visual-regexp, kregexpeditor, txt2regex (though this is a bit different). Or simply google "regexp debugger".
.
- References:
- regex, negations, grep, find and replace (a few questions)
- From: jameshanley39@xxxxxxxxxxx
- Re: regex, negations, grep, find and replace (a few questions)
- From: Moe Trin
- Re: regex, negations, grep, find and replace (a few questions)
- From: jameshanley39@xxxxxxxxxxx
- regex, negations, grep, find and replace (a few questions)
- Prev by Date: Re: regex, negations, grep, find and replace (a few questions)
- Next by Date: Re: regex, negations, grep, find and replace (a few questions)
- Previous by thread: Re: regex, negations, grep, find and replace (a few questions)
- Next by thread: Re: [LONG] Re: regex, negations, grep, find and replace (a few questions)
- Index(es):
Relevant Pages
|