Max
Max

Reputation: 35

Understanding a couple of regex expressions

I have a couple of regex expressions that I don't understand.

Why doesn't [^dp]an match the string 'pan'? I thought the regex was telling you to match any substring that contains 'd' or 'p', then 'an'. But it doesn't seem like that's what it's saying.

Also, am I interpreting <[a-z]*@\w+.edu> correctly: match characters in [a-z] 0 more times until you reach '@', then match any word character 1 or more times, then match any character except new line, then match 'edu'.

Thank you for your help.

Upvotes: 1

Views: 30

Answers (1)

zzxyz
zzxyz

Reputation: 2981

[^ means DON'T match characters in the set. Or, more accurately, match any character but characters in that set (so a character does have to be there.)

Regarding the next one, you are basically correct although missing <> which that regex also needs for a match to occur. What . means actually depends, but it usually means any character but a newline. Sometimes it can include a newline (perl, in special modes, for example)

And this may be of use to you, as it breaks down what each bit means: https://regex101.com/

Upvotes: 2

Related Questions