Solved

add range in regular expression

Posted on 2014-07-25
3
201 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
[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
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
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…

687 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