1

Does the regular expression X•(Y*+Z) accept the word X?

I would say it does, as Y=ε should fulfill the disjunction, but I'm not sure.

Corbie
  • 819
  • 9
  • 31

2 Answers2

2

Yes, matching 0 times still counts as success.

Or, looking at it from the other direction, your regex generates

X
XY
XZ
XYY
XYYY
XYYYY
...
melpomene
  • 84,125
  • 8
  • 85
  • 148
1

This answer is assuming that your regex could also be represented as X.(Y*|Z) in addition to your original of X•(Y*|Z) -- if that is not correct, please explain what is supposed to do or represent.

X•(Y*|Z) necessitates that X be present before Y* or Z can match, but will not include X in the match's specific capture-group results, only the matching line. If you wanted to include X, you might re-write it as (X)•(Y*|Z) and extract X from capture group 1, and your disjunction match in capture group 2.

kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80
  • Thanks for your answer. The • is meant to be the conjunction (logical AND). I will change my `|` to make that more intuitive. – Corbie Mar 21 '18 at 04:22