473,468 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question on Regular Expression - "optional" group

9 New Member
Hi,
I'm trying to process a large number of files, each with a very small size (about 500 chars maximum).
I need to retrieve multiple information from each file, and some of these are optional.
So to "simplify" the process, I undefed $/ (variable contains the full file).

The current regular expression that I know works (with all mandatory matches) is the following:
/\{2:[^\}]+(\d{6})\d{4}.\}.*^:25:(.+?$).*^:13D:(\d{6})/sm
as can be seen, there are 3 groups,
the part I wish to make optional is ^:13D:(\d{6})
so I thought just putting (^:13D:(\d{6}))? would be fine (managing the additional group afterwards of course),
but trying out the changed regular expression:
/\{2:[^\}]+(\d{6})\d{4}.\}.*^:25:((.+?$).*^:13D:(\d{6}))?/sm
it seems the last part never contains anything, even when the previous version did manage a match.
Can someone tell me why?
Also, if my approach is not efficient, any comment on how to better do it will be greatly appreciated. :)

Thanks in advance.

P.S.: I've been trying the script on windows [5.8.8] and unix (aix) [5.8.2],
Aug 16 '07 #1
3 3173
Rincevent
9 New Member
Ok, I kept playing around, and it seems I made 2 mistakes: :p

1/ the "changed" regular expression i presented had a typo (doesn't help when you ask for help not to provide what you used exactly

2/ i made in my first attempts this part of the regular expression optional: ^:13D:(\d{6}), while I should have gone for this one: ..*^:13D:(\d{6})
Problem was the "greedy nature of .*.

So, problem solved. :)
Aug 17 '07 #2
KevinADC
4,059 Recognized Expert Specialist
Glad you solved it. Next time post some sample data too, that always helps when trying to help with pattern matching that is a bit complex.
Aug 17 '07 #3
Rincevent
9 New Member
Thanks for the recommendations, KevinADC.
duly noted. :)
Aug 21 '07 #4

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

Similar topics

2
by: JJA | last post by:
Please advise on how to get the GROUP BY coded in an acceptable way: DECLARE @LO INT DECLARE @HI INT DECLARE @StartDate varchar(10) DECLARE @EndDate varchar(10) SELECT @StartDate =...
5
by: (Pete Cresswell) | last post by:
I've dabbled in "Optional" over the last few days and think I'm coming down against using it. Seems to me like it makes the code harder to read and more complicated. Instead of using Optional,...
2
by: robert kurz | last post by:
hallo ng, i am trying to parse a sql-statement with regular expressions. my goal is to get the parts of the statement. in my thoughts the group-functionality of the regular expressions should do...
2
by: Oenone | last post by:
In our applications, we use the special value of DateTime.MinValue to represent "null dates" throughout all our code. We recently ran into an issue where we wanted an optional date parameter for a...
2
by: Steve | last post by:
Kind of a strange question... I have a VB.NET 2.0 solution containing a main project (my EXE) and a number of other projects (class DLLs) that are "plug-ins" to the main app. These plugins get...
1
by: Sinex | last post by:
Hi, I have a webmethod. It takes an int parameter. I want this to get serialized as an XMLAttribute...so I used the XMLAttributeAttribute decoration and it works fine. Now, I want to specify...
6
by: Queez | last post by:
I've had a good look around and no-one seems to have mentioned this, which leads me to believe that I may be missing something simple. Basically, is there a way I can do the following, and if so,...
0
by: shai.halevi | last post by:
I'm looking for a simple template with the following property: I want to have in the resulting page something like this (say): <div> This is some text that never changes: ]] This is some more...
6
by: .rhavin grobert | last post by:
hello;-) i frequently need the following construction: ReturnParam § Function() § { /...do something.../ someType var § = something; /...do something.../ return something;
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.