How is the AND/OR operator represented as in Regular Expressions?

后端 未结 5 1882
独厮守ぢ
独厮守ぢ 2020-11-27 10:37

I\'m currently programming a vocabulary algorithm that checks if a user has typed in the word correctly. I have the following situation: The correct solution for the word wo

5条回答
  •  星月不相逢
    2020-11-27 11:23

    I'm going to assume you want to build a the regex dynamically to contain other words than part1 and part2, and that you want order not to matter. If so you can use something like this:

    ((^|, )(part1|part2|part3))+$
    

    Positive matches:

    part1
    part2, part1
    part1, part2, part3
    

    Negative matches:

    part1,           //with and without trailing spaces.
    part3, part2, 
    otherpart1
    

提交回复
热议问题