Forums Register Login

regex question

+Pie Number of slices to send: Send
Hello:

My requirement for a string of characters: May contain any letter, spaces, dashes or single quotes but you cannot have two consecutive spaces, two consecutive dashes or two consecutive single quotes.

I first tried to see if I could prevent just consecutive spaces. I figured this would be the correct regex:

^[a-zA-Z\-\s'-[\s{2}]]+$

or

^[a-zA-Z\\-\\s'^[\\s{2}]]+$

or

^[a-zA-Z\\-\\s'[^\\s{2}]]+$

but I haven't come up with the solution. What would be the correct regex?

Thanks.

+Pie Number of slices to send: Send
Hi,

try this pattern:

Output from this program:


Edit:
Sorry, the above pattern matches double quotes instead of single quotes,
correct pattern should be:
s.matches("^(?!.*([\\-\',\\s])\\1)[a-zA-Z\\s\\-,\']+$")
+Pie Number of slices to send: Send
Thanks! I'm going to study it to see how it works.
+Pie Number of slices to send: Send
Wait it's allowing numbers to be present

"d - '4s" is passing though but it shouldn't
+Pie Number of slices to send: Send
Sorry, my mistake
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 760 times.
Similar Threads
Seemingly simple regex making my head hurt
regex to find url
Regular expression help
regex for nameFields: first & last names tested separately
Regular expression help
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:49:33.