Regular expression, what is the difference between (T | E | N) * and [TEN] *

I play regexcrossword and get a little confused about the difference between (T|E|N)*and [TEN]*.

First, for me, read like: either T, E, or N zero until unlimited time.

The second, for me, reads: From a list of T, E or N zero to unlimited time.

I do not see the difference. Of course there is one. Thanks for the help!

+4
source share
3 answers

If you consider only letters ... then there is no difference between letters |and putting them in a character set [ ].. But this does not apply to words, etc.

Example:

(batman|superman|ironman) differs from [batmansupermanironman]

  • (batman|superman|ironman)will match any of the words batman, supermanorironman

  • [batmansupermanironman] [abeimnoprstu]

. [a-z].. , , ..

.. - , (T|E|N), , , ..:)

+9

, (T|E|N)* , .

, TENTEN, (T|E|N)* N . [TEN]*, , .

, (T|E|N)* , .

, TENTEN, , ( ):

Attempts to match T
 T E N T E N
^
Matches T, moves on
 T E N T E N
  ^
Attempts to match T
 T E N T E N
  ^
Fails, attempt to match the next, E
 T E N T E N
  ^
Matches E, moves on
 T E N T E N
    ^
Attempts to match T
 T E N T E N
    ^
Fails, attempt to match the next, E
 T E N T E N
    ^
Fails, attempt to match the next, N
 T E N T E N
    ^
Matches N, moves on
 T E N T E N
      ^

, , :

Attempts to match T, E or N
 T E N T E N
^
Matches T, moves on
 T E N T E N
  ^
Attempts to match T, E or N
 T E N T E N
  ^
Matches E, moves on
 T E N T E N
    ^
Attempts to match T, E or N
 T E N T E N
    ^
Matches N, moves on
 T E N T E N
      ^

, ( ... | ... ) , , [ ... ] " ".

, (1 ) , .. [TEN]* (T|E|N)* ( (?:T|E|N)*).

+5

.

, .


(T|E|N)*It is transmitted in a parallel query, in the tree structure it will look like this:
(T|E|N)* -> (T|E|N) -> T|E|N -> Parallel branch T, E, N
this means that the engine goes through 4 phases to process the input text to match.
[TEN]*processed as follows: [TEN]* -> [TEN]
Only 2 phases for processing input text for compliance.


Therefore [TEN]*preferable(T|E|N)*
+2
source

All Articles