473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How To get range of Value with Regular expression

Hi all,

Langage : .NET
Framework : 1.1
OS: Win XP 2000 Pro

I have this regex :

^*FOO([1-9]|1[0-3])

Which must to match with : 01_FOO1, 01_FOO10, 01_FOO13 and not to
01_FOO14, 01_FOO0

But this regex match with 01_FOO1 and 01_FOO14, but if i need to
01_FOO14 ( which
it'snt in the wanted range, it match because 01_FOO1 match the pattern.

How to do this ?

Thanks for reply

Nov 17 '05 #1
3 1210
"sl******@gmail.com" wrote:
I have this regex :

^*FOO([1-9]|1[0-3])

Which must to match with : 01_FOO1, 01_FOO10, 01_FOO13 and not to
01_FOO14, 01_FOO0

But this regex match with 01_FOO1 and 01_FOO14, but if i need to
01_FOO14 ( which
it'snt in the wanted range, it match because 01_FOO1 match the pattern.

How to do this ?


When you get a match against the first term in your alternation, [1-9], you
need to ensure that the following character is not a digit greater than 3.
Since you don't want (usually) to capture the following character in this
case you need to use a zero-width, negative, lookahead assertion. Something
like this:

"^.*FOO(1[0-3]|[1-9](?![0-9]))"

This says; first, try to match the 10, 11, 12, or 13. But if not, then
match any single digit as long as the character following that digit is not,
itself, a digit. Because we use a lookahead assertion, that following
character is not part of the captured text.

This should match FOO10, FOO11, FOO12, FOO13, and any of FOO1, FOO2,...,
FOO9, but not FOO0, FOO14, FOO42, etc.

Note: I'm entering this just off the top of my head, and there may be
problems with it, but I believe this is the type of approach you will need.

-- Tom
Nov 17 '05 #2
In article <11**********************@g47g2000cwa.googlegroups .com>,
<sl******@gmail.com> wrote:

: I have this regex :
:
: ^*FOO([1-9]|1[0-3])

I assume you mean ^.*FOO([1-9]|1[0-3]) -- i.e., caret, dot-star.

: Which must to match with : 01_FOO1, 01_FOO10, 01_FOO13 and not to
: 01_FOO14, 01_FOO0
:
: But this regex match with 01_FOO1 and 01_FOO14, but if i need to
: 01_FOO14 (which it'snt in the wanted range, it match because 01_FOO1
: match the pattern.

Is there anything else in the input?

If these FOO values are all that's there, then anchor your pattern
on the end with $ to prevent 01_FOO14 from matching. Otherwise,
bookend your pattern with whatever follows.

Greg
Nov 17 '05 #3
Thanks for your reply.

Effecively Tom, I did'nt think by the negative. I note for the later.
This approach is, in my case, effective and elegant.

I has test it and that works.

Thanks, and have fun code with .NET
Le Saint

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bissatch | last post by:
I am trying to compare two variable but using regular expression: $access = "glasgow" $areaid = "glasgow-westend-byers_rd" using the two variables, I would like the areaid variable to be...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
1
by: tshad | last post by:
I have been trying to set up a range validator and regular expression for my dates. I tried this: <asp:RangeValidator runat="server" ControlToValidate="AbsentFrom1" MinimumValue="12/31/1950"...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
2
by: Herbert C. Brown, Jr. | last post by:
To whomever may assist, I am trying to code an index (TLE - Tagged Logical Element) identifier to load a customer statement into OnDemand (an archival system created by IBM). The TLE is defined...
8
by: Rahul | last post by:
Hello Everyone, I was wondering what is the datatype of obj? Is it an integer? If so what if the number of enumerations crosses over the limit of an integer (2^32-1)? enum { CLUB, DIAMONDS
14
by: Jim Langston | last post by:
The output of the following program is: 1.#INF 1 But: 1.#INF 1.#INF was expected and desired. How can I read a value of infinity from a stream?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.