Hey. I have a regex question. Consider user input like: foo bar foo_bar foo-bar I need to make sure that these possibilities exist but only these three. The following regex works: (_|-| )? As in: foo(_|-| )?bar But I was wondering,is there any alternative that is nicer to read? I am especially wondering because at some later time, perhaps I may need to enable more character tokens, such as ',' so my example may become fairly long eventually in the long run.
on 2016-10-25 14:04
on 2016-10-25 20:21
This one should work : /foo[\s_\-]bar/
on 2016-10-26 18:06
Robert Heiler wrote in post #1185181: > Hey. > > I have a regex question. > > Consider user input like: > > foo bar > foo_bar > foo-bar > > I need to make sure that these possibilities exist but only > these three. > > The following regex works: > > (_|-| )? [...] Have you yet noticed that that regex doesn't match only those 3 inputs due to the ?-quantifier?