473,382 Members | 1,437 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,382 software developers and data experts.

Regular Expression Logic problem

karlectomy
Hey all,

I have a parsing application where I am taking text files and choppiing them up (so to speak) There are small formatting differences which I was hoping to take care of with regular expression logic.

Here is example of one line:

$CHAP_01.txt$ 1 Chapter One

This line should be equivalent:

$CHAP_01.txt$ 1. Chapter One

(See the period after the one?)

I am using the split function with the regular expression " \\d+ " which works fine for the first one but for the second, I get an out of bounds exception when I refer to index 1 in the output array.

I was wondering if there was some way to use " \\d+ [ \\d+\\. ]" or some other logic in the regular expressions to split those two line s the same..

THanks

Karl
Dec 3 '07 #1
5 1486
JosAH
11,448 Expert 8TB
Hey all,

I have a parsing application where I am taking text files and choppiing them up (so to speak) There are small formatting differences which I was hoping to take care of with regular expression logic.

Here is example of one line:

$CHAP_01.txt$ 1 Chapter One

This line should be equivalent:

$CHAP_01.txt$ 1. Chapter One

(See the period after the one?)

I am using the split function with the regular expression " \\d+ " which works fine for the first one but for the second, I get an out of bounds exception when I refer to index 1 in the output array.

I was wondering if there was some way to use " \\d+ [ \\d+\\. ]" or some other logic in the regular expressions to split those two line s the same..

THanks

Karl
You want a literal dot at the end zero or more times; regular expressions can
easily take care of that: \.?

That is: a literal dot (escaped) with a closure ? (zero or one times). Of course
you have to use two backslashes it you want to put that regular expression in
a literal string: \\.?

kind regards,

Jos
Dec 3 '07 #2
You want a literal dot at the end zero or more times; regular expressions can
easily take care of that: \.?

That is: a literal dot (escaped) with a closure ? (zero or one times). Of course
you have to use two backslashes it you want to put that regular expression in
a literal string: \\.?

kind regards,

Jos
Thanks Jos,

That works! but I also figured it out on my own using " \\d+(\\. | )" which is a dot followed by a space or just a space.

THanks for your help,

Karl
Dec 3 '07 #3
JosAH
11,448 Expert 8TB
Thanks Jos,

That works! but I also figured it out on my own using " \\d+(\\. | )" which is a dot followed by a space or just a space.

THanks for your help,

Karl
Yep, you're welcome of course; when you use regular expressions there are more
ways that lead to Rome ;-)

kind regards,

Jos
Dec 3 '07 #4
Yep, you're welcome of course; when you use regular expressions there are more
ways that lead to Rome ;-)

kind regards,

Jos
That's very true and also, com.cities.rome wasn't built in a day :)
Dec 3 '07 #5
JosAH
11,448 Expert 8TB
That's very true and also, com.cities.rome wasn't built in a day :)
True; and don't forget: when in Rome do as the Romans do.

kind regards,

Jos (<--- walks like an Egyptian ;-)
Dec 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: radawson218 | last post by:
Hi, I'm a complete newbie when using regular expressions, so forgive me if my delimma sounds stupid. I have an ASP.NET app that utilizes url rewriting. It's a simple bookstore that allows...
2
by: Christian Staffe | last post by:
Hi, I would like to check for a partial match between an input string and a regular expression using the Regex class in .NET. By partial match, I mean that the input string could not yet be...
8
by: Natalia DeBow | last post by:
Hi, I am stuck trying to come up with a regular expression for the following pattern: A string that contains "/*" but that does not contain */ within it. Basically I am searching for C-style...
3
by: ksr | last post by:
Hi, I am looking for a regular expression that would extract UNC paths from a given string and place that inside a href. Currently the expression fails if there is a space in the path.. eg....
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
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...
0
by: ahropak | last post by:
Hi, I have a question regarding a regular expression within Regex.Split() method which will help me to break each line of code into tokens. I'm trying to parse some lines of C# source code and...
8
by: Nicodemas | last post by:
Hello all, could not find a regular expression forum, so I thought I would post it to my favorite of the forums. I have a series of applications I've developed which all use a centralized...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.