Need help understanding this particular regular expression [^.]

phan
[^.]+\.(txt|html)

I am learning regex, and am trying to parse this.

[^.] The ^ means "not", and the dot is a wildcard that means any character, so this means find a match with "not any character"? I still don't understand this. Can anyone explain?

The plus is a Kleene Plus which means "1 or more". So now it's "one or more" "not any character".

I get \., it means a period.

(txt|html) means match with a txt file or html file. I think I understand everything after the plus sign. What I don't understand is why it doesn't look something the DOS equivalent where I can just do this: *.txt or *.(txt|html) where * means everything that ends in the file extension .txt or .html?

Is [^.] the equivalent of * in DOS?

Amal Murali

The dot (.) has no special meaning when it's inside a character class, and doesn't require to be escaped.

[^.] means "any character that is not a literal . character". [^.]+ matches one or more occurrences of any character that is not a dot.

From regular-expressions.info:

In most regex flavors, the only special characters or meta-characters inside a character class are the closing bracket (]), the backslash (\), the caret (^), and the hyphen (-). The usual meta-characters are normal characters inside a character class, and do not need to be escaped by a backslash. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Need help understanding this particular regular expression [^.]

From Dev

Help with understanding a regular expression

From Dev

Need help in this Regular Expression

From Dev

Need for help in this scrapy regular expression

From Dev

Need help for writing regular expression

From Dev

Need help to create regular expression in Java

From Dev

Python - re - need help for regular expression

From Dev

Need Help to Understand Regular Expression Immediately

From Dev

Need help to resolve regular expression for Table of Contents

From Dev

Need help constructing Regular expression pattern

From Dev

Need regular expression to find all substring of a particular pattern

From Dev

.net regular expression - need help merging 'two' expressions

From Dev

Need Help In Regular Expression - Match 6 digits after specific word

From Dev

Need help completing this regular expression that captures relative paths in HTML

From Dev

Regular Expression - Need Help Matching Everything Except For A Certain String

From Java

Need help in understanding Scale

From Dev

Need help understanding this operation

From Dev

Dagger: need help in understanding

From Dev

Need help understanding this line

From Dev

Need help understanding an algorithm

From Dev

Regular Expression Help - Lookahead

From Dev

Help with regular expression

From Dev

want help on regular expression

From Dev

Help with regular expression in grep

From Dev

Regular expression help

From Dev

Understanding Regular Expression in Javascript

From Dev

Understanding Regular Expression in Javascript

From Dev

Python regular Expression understanding

From Dev

regular expression to find a particular code

Related Related

HotTag

Archive