473,396 Members | 2,140 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,396 software developers and data experts.

regex problem

Hi,

Here is another problem I am having, after discovering
regular expressions are available in vb.net std 2002.

I have a line read from file that produces the following
string:

inputln = "1.0 kt 1.6878099 ft/sec"

I tried this (below) and it does not work, and I cannot
figure out why (excuse the clunkiness please)

trying to get

units_typ_io_count(1, 1, count_speed)=1.0

code snippet

Dim units_typ_io_count(4, 2, 0) As Double
Dim riou As New Regex("?<numrtr>^\d+\.\d+([eE][+ -]\d+)?
[^ ].*?<dentr>\d+\.\d+([eE][+ -]\d+)?[ ]+?<outunits>
[^ ].+$", RegexOptions.Compiled)
..
..
..
ReDim Preserve units_typ_io_count(4, 2, 1)
units_typ_io_count(1, 1, 1) = CDbl(riou.Match
(inputln).Result("${numrtr}"))

Thanks for the help

Bob Lambert

Nov 20 '05 #1
3 1171
Bob,

I tried the following regular expression:

(?<numrtr>^\d+\.\d+([eE][+ -]\d+)?).*(?<dentr>\d+\.\d+([eE][+ -]\d+)?)+(?<ou
tunits>.+$)

using this test string: 1.0e-10 kt 1.6878099e+6 ft/sec

it returned the following named groups:
numrtr: 1.0e-10
dentr: 1.6878099e+6
outunits: ft/sec

Is this close to what you were trying to do? If so, note that I had to make
a few changes to your regular expression to accomplish it.

I tested this using Expresso, which is available at:

http://www.ultrapico.com

Jim
Nov 20 '05 #2
Jim,

Thanks for the feedback. I finally got it to work by
removing the <numrtr> and other parameters. Instead, I
enclosed the parts I wanted in parentheses, and referred
to them in the .result as below.

Not sure why the <name> deal would not work.

Bob

input string:
1.0 kt 1.6878099 ft/sec

code:
Dim riou As New Regex("^(\d+\.\d+([eE][+ -]\d+)?) [^ ].*
(\d+\.\d+([eE][+ -]\d+)?)[ ]+?([^ ].+)$", _
RegexOptions.Compiled)
..
..
..
units_typ_io_count(1, 1, 1) = CDbl(riou.Match
(inputln).Result("${1}"))
units_typ_io_count(1, 2, 2) = CDbl(riou.Match
(inputln).Result("${3}"))
units_desc_typ_count(1, 1) = riou.Match(inputln).Result
("${5}")

output:
units_typ_io_count(1, 1, 1) = 1.0
units_typ_io_count(1, 2, 2) = 1.6878099
units_desc_typ_count(1, 1) = "ft/sec"

-----Original Message-----
Bob,

I tried the following regular expression:

(?<numrtr>^\d+\.\d+([eE][+ -]\d+)?).*(?<dentr>\d+\.\d+ ([eE][+ -]\d+)?)+(?<outunits>.+$)

using this test string: 1.0e-10 kt 1.6878099e+6 ft/sec

it returned the following named groups:
numrtr: 1.0e-10
dentr: 1.6878099e+6
outunits: ft/sec

Is this close to what you were trying to do? If so, note that I had to makea few changes to your regular expression to accomplish it.
I tested this using Expresso, which is available at:

http://www.ultrapico.com

Jim
.

Nov 20 '05 #3
Your original expression did not enclose the named capture within
parenthesis. You need to use the following syntax:

(?<name>matchsting)

rather than:

?<name>matchstring

Jim

"bob lambert" <na*******@cinci.rr.com> wrote in message
news:03****************************@phx.gbl...
Jim,

Thanks for the feedback. I finally got it to work by
removing the <numrtr> and other parameters. Instead, I
enclosed the parts I wanted in parentheses, and referred
to them in the .result as below.

Not sure why the <name> deal would not work.

Bob

Nov 20 '05 #4

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

Similar topics

3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
6
by: Talin | last post by:
I've run in to this problem a couple of times. Say I have a piece of text that I want to test against a large number of regular expressions, where a different action is taken based on which regex...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
7
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.