Solved

add range in regular expression

Posted on 2014-07-25
3
193 Views
Last Modified: 2014-08-06
I have this VBScript regex pattern. How can I make it restrict the range it finds from 39 to 302?

it mustnt pick up 30 for example as 30 is in 302


StrPattern = "^\s*(\S+(?=\s).*?)(?:([^\d.])\d+$|\(?\d* ?bhp?\d*\)?|\(\d+\)|\[\d{2,3}\]|\d{3})"
0
Comment
Question by:PeterBaileyUk
  • 2
3 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 40220219
Which part of the pattern do you want to restrict to between 39 and 302?  In general, this is how you could do it:
39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2]

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 40223507
Current pattern ignores the first word in a string then picks up and number, I need to restrict the numbers it finds to the range given.
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 40224537
It looks like you are picking up numbers in several different locations.  If you just combine my pattern with yours (just replace your \d* or \d+ matches with my pattern), it should work:
StrPattern = "^\s*(\S+(?=\s).*?)(?:([^\d.])(?:39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2])$|\(?(?:39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2])? ?bhp?(?:39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2])?\)?|\((?:39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2])\)|\[(?:39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2])\]|(?:39|[4-9][0-9]|[1-2][0-9][0-9]|30[0-2]))"

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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,…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now