473,387 Members | 1,669 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.

Regexp matching blocks of text

Hi,
I'm using RegExp to try and match a particular string value and can't figure
out why it's not working!

Possible valid values for the string are EITHER a single number (any length
of digits) OR a series of numbers, delimited by "|". (e.g. valid examples are
"1", "123", "123|", "123|456|", etc. The following would be invalid, "|",
"|123").

I've tried several things but only ever seem to match the first part e.g. :

(\d+\|)*|\d+ will match "123|" but not "123"
\d+|(\d+\|)* will match "123" but not "123|"

I eventually also want to anchor this with ^ and $. Can someone spot what's
wrong?
Thanks!

Feb 5 '07 #1
2 1363
Hi,
I'm using RegExp to try and match a particular string value and can't
figure
out why it's not working!
Possible valid values for the string are EITHER a single number (any
length of digits) OR a series of numbers, delimited by "|". (e.g.
valid examples are "1", "123", "123|", "123|456|", etc. The following
would be invalid, "|", "|123").

I've tried several things but only ever seem to match the first part
e.g. :

(\d+\|)*|\d+ will match "123|" but not "123"
\d+|(\d+\|)* will match "123" but not "123|"
I eventually also want to anchor this with ^ and $. Can someone spot
what's
wrong?
Thanks!
Try \d+(\|\d+)* or (\d+|)*\d+

Hans Kesting
Feb 5 '07 #2
Hi, your reply led me to look at the problem a little differently! I decided
to go with:

^\d+([\|(\d+)])*$

I think this is the exact validation I need (it's basically your first
version with a few extra brackets)

Thanks a million!

"Hans Kesting" wrote:
Hi,
I'm using RegExp to try and match a particular string value and can't
figure
out why it's not working!
Possible valid values for the string are EITHER a single number (any
length of digits) OR a series of numbers, delimited by "|". (e.g.
valid examples are "1", "123", "123|", "123|456|", etc. The following
would be invalid, "|", "|123").

I've tried several things but only ever seem to match the first part
e.g. :

(\d+\|)*|\d+ will match "123|" but not "123"
\d+|(\d+\|)* will match "123" but not "123|"
I eventually also want to anchor this with ^ and $. Can someone spot
what's
wrong?
Thanks!

Try \d+(\|\d+)* or (\d+|)*\d+

Hans Kesting
Feb 5 '07 #3

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

Similar topics

19
by: Magnus Lie Hetland | last post by:
I'm working on a project (Atox) where I need to match quite a few regular expressions (several hundred) in reasonably large text files. I've found that this can easily get rather slow. (There are...
1
by: joh12005 | last post by:
Hello, here is a trouble that i had, i would like to resolve it with python, even if i still have no clue on how to do it. i had many small "text" files, so to speed up processes on them, i...
6
by: Rizyak | last post by:
******************** alt.php.sql,comp databases.ms-sqlserver microsoft.public.sqlserver.programming *********************************** Why doesn't this work: SELECT * FROM 'Events'
3
by: Jane Doe | last post by:
Hello, I need to browse a list of hyperlinks, each followed by an author, and remove the links only for certain authors. 1. I searched the archives on Google, but didn't find how to tell the...
3
by: jasonkester | last post by:
Just a heads up for anybody that comes across this in the future. Noticed a strange behavior in RegExp.test() today. Check out the following code. It will alternately display "chokes" and null,...
6
by: papa.coen | last post by:
Hi, I need to split/match the following type of (singleline) syntax on all commas (or text in between) that are not between qoutes: A,'B,B',C,,'E',F The text between quotes can be _any_ text...
7
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
4
by: r | last post by:
Hello, It seems delimiters can cause trouble sometimes. Look at this : <script type="text/javascript"> function isDigit(s) { var DECIMAL = '\\.'; var exp = '/(^?0(' + DECIMAL
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.