What does it mean [_ | \ _ | \.]? in javascript regular expressions?

I have js code:

/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/

But what's the point [_|\_|\.]? (js regexp)

+4
source share
4 answers

If we use a resource like Regexper , we can visualize this regular expression:

Example

From this we can conclude that [_|\_|\.]requires one of the "_", "|" or ".". We also see the double declaration "_" and "|" not required. As a HamZa comment , this segment can be shortened to [_|.]achieve the same result.

, , Regexper, .

+11

, .
. .

[|_.]

+5

REGEX101 -  

Char class [_|\_|\.] 0 to 1 times [greedy] matches:

[_|\_|\. One of the following characters _|_|.
 [_|\_|\.] requires one of either "_", "|" or "."

. RegEx101

+5

[_|\_|\.], , (_) (.) [_.].

, (|) "" (.. alternation), . , , , . .

(.) - , , . , , . ; , , .

, ? . , , . , - , ( ), - , . :

[a-zA-Z0-9]+([_.][a-zA-Z0-9]+)*

- , _ ., . , , . , , , , . , , , , . , , .

+3

All Articles