Solved

add range in regular expression

Posted on 2014-07-25
3
197 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a regex for dollar amount validation 4 80
regular expression for 10 digit number 7 98
Help with a regex 3 62
Reg Exp to extract Url from string asp 12 40
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…

726 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