[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:My first piece of advice is to not do the whole thing in a regular expression. You can write a simple regular expression for 4-32 alphanumeric characters. Then just add an if statement to check the string contains a number.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:I have to disagree with this. It is very easy to check for 4-32 alphanumerics and very easy to use a positive lookahead to look for a decimal digit. I would post the solution but won't until there is something that shows the OP has put some effort into this.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
naveen gupta wrote:below is my regular expression
[a-zA-z_0-9]{4,32}
i can easily add condition for minimum single digit at the start or at the end of the regular expression but couldn't find any info online for adding anywhere in the expression
any reference to website is also ok, i can figure it out
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Jeanne Boyarsky wrote:
James Sabre wrote:I have to disagree with this. It is very easy to check for 4-32 alphanumerics and very easy to use a positive lookahead to look for a decimal digit. I would post the solution but won't until there is something that shows the OP has put some effort into this.
That's true. I was thinking that the problem was hard for arbitrary counts. For one, you are correct that lookahead is just fine. Which is the actual problem here.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:one just needs a repeat count {n} inside the look ahead and allowing an arbitrary number of non-decimals between the decimals.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
naveen gupta wrote:here you go
"(?=\\w{4,32})\\w*\\d+\\w*"
THANKS FOR THE INPUTS
by the way, i wanted the digit to appear anywhere in the alphanumeric value. For that reason, i had to use lookaround instead of lookahead and lookbehind
regular expressions are very interesting topic
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
naveen gupta wrote:33 characters is working fine
using lookahead, i have to write expression saying find so and so after this
but in my case single digit CAN appear anywhere in the string, first, middle or last of the string
So how does lookahead will help in my case?
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Whatever you say buddy! And I believe this tiny ad too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|