• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

regular expression java

I am writing a business rule, where the value should be between 1X - 126Y

which means it taken values 1X , 2X... 126X ,  and 1Y , 2Y.. 126Y

can you please help me with that?

Regards
0
akp007
Asked:
akp007
  • 4
  • 3
  • 2
  • +2
1 Solution
 
käµfm³d 👽Commented:
If I understand your requirement correctly, then you can try:

^(12[0-6]|1[0-1]\d|[1-9]\d|[1-9])[XY]$

Open in new window

0
 
CEHJCommented:
Sounds to me like you need to parse into an int and evaluate arithmetically
0
 
slightwv (䄆 Netminder) Commented:
Can you provide more about your requirements?

How are the values stored(is this where Oracle comes into the question)?
How are the search values provided?

Just a guess here:
You have some value and you want both the number portion and letter portion to be between some data set.

So 9G will be between 1A and 10H but not 1H and and 9G will be between 1A and 100Z but not 10A and 13H?

If so, how are the start and end ranges stored?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
akp007Author Commented:
this is regular expression question. we have business rules with drools.

User should enter the values between 1X and 126Y

the answer given by kaufmed works.. But it is not validating..

Let say if enter 11Y , 20X, 40Y etc..,

means it working for any value (11-119)XY

thanks for helping me out
0
 
Terry WoodsIT GuruCommented:
@kaufmed's pattern looks good to me. Are you using the Java regex functions directly (if so, perhaps you could show us the code), or is the pattern applied through some other means?

Also can you please explain what you mean by saying it works, but is not validating?
0
 
akp007Author Commented:
this is how I  am using

scenario.getString("MyString").trim().matches("^(12[0-6]|1[0-1]\d|[1-9]\d|[1-9])[XY]$")==false);  


Thanks
0
 
käµfm³d 👽Commented:
You need to double up the backslashes--since this is Java:

scenario.getString("MyString").trim().matches("^(12[0-6]|1[0-1]\\d|[1-9]\\d|[1-9])[XY]$")==false);

Open in new window

0
 
akp007Author Commented:
It worked thanks a lot , only bit of change that I had to was

matches("^(12[0-6]|1[0-1]\\\\d|[1-9]\\\\\d|[1-9])[XY]$")==false)

Regards
0
 
käµfm³d 👽Commented:
Doh! I forgot you need quadruple backslashes in Java. Good catch   = )
0
 
Terry WoodsIT GuruCommented:
I don't think you need to quadruple them unless you're wanting to match a literal backslash character, but perhaps I'm missing something...
0
 
käµfm³d 👽Commented:
Terry, you may be right. I didn't plug it into Java to test. I just remember having to do so one other time that I was working in Java. Perhaps I was trying to match a UNC path, though.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now