Nirmal Mukundan wrote:
Nirmal Mukundan wrote:
"Only alpha and numeric characters, apostrophes and hyphens are acceptable. Spaces must
not appear immediately before or after apostrophes and hyphens".
For this I tried using many formats and finally I had something nearby
Henry Wong wrote:
Perhaps the Oracle tutorial on regular expressions is a good place to start here ... http://docs.oracle.com/javase/tutorial/essential/regex/
Nirmal Mukundan wrote:"Only alpha and numeric characters, apostrophes and hyphens are acceptable. Spaces must
not appear immediately before or after apostrophes and hyphens".
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Nirmal Mukundan wrote: As Richard said, I should be checking the expression dividing it into 2.
Nirmal Mukundan wrote:
Kindly help me with the regex.
Winston Gutkowski wrote:
My advice: Don't try to do it all in one regex.
Like Richard says, those "negative lookahead/lookbehind" searches are quite advanced stuff and difficult to follow.
Henry Wong wrote: and this is for a something that needs to be supported, then I recommend not using regular expressions at all. Regexes can get really complex, even for simple stuff, in the hands of a beginner -- and the last thing that you want is to create write-only code that can't be supported.
Nirmal Mukundan wrote:
So as per the requirement, "Only alpha and numeric characters ,white space, apostrophes and hyphens are acceptable. Spaces must
not appear immediately before or after apostrophes and hyphens".
Kindly help me with the regex.
Ramesh-X
Ramesh Pramuditha Rathnayake wrote:
Nirmal Mukundan wrote:
So as per the requirement, "Only alpha and numeric characters ,white space, apostrophes and hyphens are acceptable. Spaces must
not appear immediately before or after apostrophes and hyphens".
Kindly help me with the regex.
Try this regex.. You will get your requirement...!!
This will work..
Henry Wong wrote:
I really like this solution -- it almost works, and does so without using any look-aheads/look-behinds. I have to admit that I tend to abuse zero length look-aheads and look-behinds, so when I see a solution (that doesn't use any) for a use case that I think obviously needs it, I find the solution elegant. It does have a couple of minor flaws that can be easily fixed though -- it doesn't allow more than one whitespace in a row, and it doesn't allow the input to end in a whitespace, apostrophe, or hyphen (neither of these conditions were specified in the requirements).
Henry
Ramesh-X
Ramesh Pramuditha Rathnayake wrote:
I did consider about not allowing white spaces at start and end. It was done by chance..!
But I intend not to use more whitespaces in a row in one time..
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|