-6

I'm studying a Java code that uses the regular expression "( *|)". What does the pipe do in this expression?

So far I understood it works the same way as the expression for a group of optional spaces, i.e. "( *).

Jindřich Mynarz
  • 1,481
  • 1
  • 18
  • 30

2 Answers2

1

Pipe ('|') simply means 'or'. At the one side we have regex for zero or more spaces, on the other side we have nothing - so it will match zero or more spaces or an empty string.

Vel
  • 504
  • 4
  • 11
1

It Indicates that a match can be one of the two terms on either side of the pipe.

look here

Raizzen
  • 192
  • 13