369-5 Advanced Regular Expressions: Question


question_369_5_b

Hi,

I’m just wondering why pattern_wrong is ruling out more than pattern.
Also is it necessary to do |.$ at the end of the pattern? I would still get the correct answer without it. I thought (?![+.]) would already rule out all the periods after [Cc].

Many thanks!

1 Like

can you add the link to it for some context

this is the lesson.

This indicates the end of the string
If a caret (^) is at the beginning of the entire regular expression, it matches the beginning of a line.

If a dollar sign ($) is at the end of the entire regular expression, it matches the end of a line.

@OlutokiJohn a caret at the start of a cell means negation.

2 Likes

My question is: why does the negation rule out every item that ends with a C or c ? Thanks!

@cy.ericson

[+] matches + in a string. [.] matches . in a string.

[.+] matches a . and + in a string.

[^.+] do not match a . and + in a string.

This regex, [Cc][^.+], will not match occurrences with C., C+, c., c+.

So where you have C or c ending a sentence, the regex ignores them.

1 Like

@monorienaghogho

[Cc][^.+], will not match occurrences with C., C+, c., c+.
[^.+] do not match a . and + in a string.

Wouldn’t it match a sentence that ends with C,c then, if the above statement is true? I didn’t negate C or c, I only negated . +

Like I imagine it be like : whateverstring C+ wont match
but whateverstring C would match

because [^.+] is taking out all the .+
So I did a test run to see what is being eliminated

and all the strings are ending with either C or c.

Many Thanks!

@cy.ericson

Try it out on regex101.com

Do not confuse .+, [.]+ and [.+].

When a special character is inside a cell, it is escaped.

It is no longer a special character, it is now its literal symbol.

3 Likes