Solved

regular expression java

Posted on 2014-04-07
12
208 Views
Last Modified: 2014-04-09
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
Comment
Question by:akp007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39984315
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 39984359
Sounds to me like you need to parse into an int and evaluate arithmetically
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39984650
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:akp007
ID: 39984722
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39984725
@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
 

Author Comment

by:akp007
ID: 39984825
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
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39984858
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
 

Author Closing Comment

by:akp007
ID: 39986159
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39987364
Doh! I forgot you need quadruple backslashes in Java. Good catch   = )
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39990325
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39990337
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question