trupti nigam wrote:I need to do below check on the entered string.
No Special character other than colon,hyphen,period and underscore are entered.
In order to achieve this I do the below, but that experession is not effective for the hyphen(-). What I need to change to include hyphen in the ignore list.
In the above pattern, if I include -, it does not work.
Also how to achieve below,
The String should not have sequence of multiple consecutive special chars. How do I check this?
Richard Tookey wrote:1) Since '-' is used as a meta character when within a character set it must be the first or last member of the set to have it's natural meaning.
2) You can refer to a previous group content using "\n" where n is the group number. So, assuming you only have the one capturing group, then two consecutive characters the same is detected using "(.)\1" .
trupti nigam wrote:
Richard Tookey wrote:1) Since '-' is used as a meta character when within a character set it must be the first or last member of the set to have it's natural meaning.
2) You can refer to a previous group content using "\n" where n is the group number. So, assuming you only have the one capturing group, then two consecutive characters the same is detected using "(.)\1" .
Can you explain 2) further by writing some example.
thanks
Pradnya
Richard Tookey wrote:
trupti nigam wrote:
Richard Tookey wrote:1) Since '-' is used as a meta character when within a character set it must be the first or last member of the set to have it's natural meaning.
2) You can refer to a previous group content using "\n" where n is the group number. So, assuming you only have the one capturing group, then two consecutive characters the same is detected using "(.)\1" .
Can you explain 2) further by writing some example.
thanks
Pradnya
Err ... Assuming you are referring to my second point - I have given an example!
trupti nigam wrote:
So Does that mean I need to do below.
trupti nigam wrote:...The String should not have sequence of multiple consecutive special chars. How do I check this?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
What I will say is: don't try to do this all in one regex.
Richard Tookey wrote:
Winston Gutkowski wrote:
What I will say is: don't try to do this all in one regex.
The Devil is in the context but the OP has not provided one. Reading between the lines ( i.e. guessing what the OP wants ) this should be simple to do in one regex using an "or" so one regex is probably OK but we will see when the context is posted.
Richard Tookey wrote:
Winston Gutkowski wrote:
What I will say is: don't try to do this all in one regex.
The Devil is in the context but the OP has not provided one. Reading between the lines ( i.e. guessing what the OP wants ) this should be simple to do in one regex using an "or" so one regex is probably OK but we will see when the context is posted.
trupti nigam wrote:
I am not sure when you say I have not provided the context. Let me try again.
trupti nigam wrote:
String name= "alex:zang%^";
Now the regex should detect that in the above string the second portion of the string after ":" has consecutive special chars exluding [^a-zA-Z0-9:_.-] and it should reject it.
But if the String is like"alex:zang" or "AlexZang" it should pass the test.
But again if the second portion of the string i.e. zang has any single special char it will fail with my previous line of code like below.
HAve I made it clear?
So, you only want it to be considered as having a special character only if two or more of them exist consecutively? Then your regex should be ... "[^a-zA-Z0-9:_.-]{2,}"
Henry
trupti nigam wrote:
Ok Let me rephrase above.
1. No Special chars other than colon,hyphen,period and underscore are entered
2.The string does not have sequence of multiple consecutive special chars
This is what I was told.
trupti nigam wrote:1. No Special chars other than colon,hyphen,period and underscore are entered
2.The string does not have sequence of multiple consecutive special chars
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
trupti nigam wrote:I am able to achieve both the conditions using below code.
trupti nigam wrote:
Ok Let me rephrase above.
1. No Special chars other than colon,hyphen,period and underscore are entered
2.The string does not have sequence of multiple consecutive special chars
So the above means the check should fail for below:
alexzang==> pass
alex:zang==>pass
alex%zang==> fail
alex.zang==>pass
alex..zang==>fail
alex.*zang==>fail
alex::zang==>fail
alex$%^zang==>fail
alex._zang==>fail
This is what I was told.
Don't get me started about those stupid light bulbs. |