Re: regex, negations, grep, find and replace (a few questions)



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".
.



Relevant Pages

  • Re: function to match parenthesis ( and )
    ... to have a collection with all matching subelements. ... There some case about little changes where the regex modification is ... function between the first parenthesis to match. ... >>> inappropriate places to apply regular expressions. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: What exactly is this simple regex doing?
    ... the regex to be matching anything except ... You're by saying that the dot in a class is not ... ||>> truncates an absolute url from first character to the one before ...
    (perl.beginners)
  • Re: problem using Regex in a C# addin
    ... Macros in VS.Net don't use the .Net regular expressions synatx, ... > i'm trying to comment out a statement in an addin using Regex with the ... > special character so that the statements can be restored at a later ... > string s, t, sPattern; ...
    (microsoft.public.vsnet.ide)
  • Re: Help: How to add a character in the line
    ... I'm a Linux user, I'd like to know how to use sed or other command to add ... possible about regular expressions and the syntax of 'sed'. ... available with the regex library only on _some_ systems (while the '+' ... or even avoid the character classes which cannot be assumed on old ...
    (comp.unix.shell)
  • regular expressions, substituting and adding in one step?
    ... Now, matching the middle part and replacing it with '%s' is easy, but how would I add the extra string to the end of the line? ... Is it done all at once, or must I make a new regex to match? ... So the questions are, how do you use regular expressions to add text to the end of a line, even if you aren't matching the end of the line in the first place? ...
    (comp.lang.python)