Solved

add range in regular expression

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fixing some Issues with regex again 9 22
REGEXREPLACE 5 50
Regex Help 2 29
Regular Expression to find values of a certain lenght 1 28
I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
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…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now