Reputation: 7
I have a paragraph like this:
"Nothing is worth more than the truth.
I like to say hello to him.
Give me peach or give me liberty.
Please say hello to strangers.
I'ts ok to say Hello to strangers."
I want to result:
"Nothing is worth more than the truth.
Give me peach or give me liberty."
if a line uses the word "hello" then remove that line and take only the line without that word.
I find some information in reference:
so I think ít as follow: regexp "^[^hello]" $line but it doesn't work
Upvotes: 0
Views: 62
Reputation: 1863
There are several problems with your attempt of:
regexp "^[^hello]" $line
A good practice with Tcl regular expressions is to put your regex inside curly braces instead of double quotes. Square brackets inside double quotes will be evaluated by Tcl as a command.
^
means the beginning of the line in regular expression.
Characters inside square brackets in a regular expression are considered a "character-class". [^hello]
does not mean the opposite of matching "hello". Instead, it matches a single character that is not h
, e
, l
, or o
.
Do you care about case? If not, then add -nocase
.
A Tcl expression, which you can use in an if
statement to check that a line does not include "hello" (or "Hello") is simply this:
![regexp -nocase {hello} $line]
Upvotes: 1