Solved

add range in regular expression

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a string in a sentence using regex 7 21
Reg Ex Issue 1 348
Need Regex Money No $ 5 69
REReplaceNoCase help 1 18
by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
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…
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…

867 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

13 Experts available now in Live!

Get 1:1 Help Now