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

Help with regular expresion

LEM
Hi,

I'm trying to use Regex to find a string inside a text buffer.
I am trying to find this pattern:

<B>1.33594 VAL</B>

where 1.33594 is a number that may change. My problem is to find a
regular expression that can read that and extracts the number.

I have tried with the following but I don't get any matches back

string pattern = @"(<B>?<MyValueUSD</B>)";

Any ideas?

Thanks!
Apr 3 '07 #1
6 1207
LEM,

Why use a regular expression for this? You know that you will have the
string wrapped in <Band </B>, you also know there will be a space, along
with up to three characters after it. Everything else is a number. It
would be very easy to code this up without regular expressions.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"LEM" <an*******@nospam.comwrote in message
news:O5**************@TK2MSFTNGP02.phx.gbl...
Hi,

I'm trying to use Regex to find a string inside a text buffer.
I am trying to find this pattern:

<B>1.33594 VAL</B>

where 1.33594 is a number that may change. My problem is to find a
regular expression that can read that and extracts the number.

I have tried with the following but I don't get any matches back

string pattern = @"(<B>?<MyValueUSD</B>)";

Any ideas?

Thanks!

Apr 3 '07 #2
LEM

So do you suggest to go character by character until I find my pattern?
The text buffer can be very big.

Nicholas Paldino [.NET/C# MVP] wrote:
LEM,

Why use a regular expression for this? You know that you will have the
string wrapped in <Band </B>, you also know there will be a space, along
with up to three characters after it. Everything else is a number. It
would be very easy to code this up without regular expressions.

Hope this helps.
Apr 3 '07 #3
LEM wrote:
Hi,

I'm trying to use Regex to find a string inside a text buffer.
I am trying to find this pattern:

<B>1.33594 VAL</B>

where 1.33594 is a number that may change. My problem is to find a
regular expression that can read that and extracts the number.

I have tried with the following but I don't get any matches back

string pattern = @"(<B>?<MyValueUSD</B>)";

Any ideas?

Thanks!
The ?<namepart is part of the (?<name>...) construction, and can't be
placed anywhere but directly after the starting parenthesis. It just
specifies the name of the group, and doesn't consume any characters in
the match, so you also have to specify a pattern for the digits.

Try this:

<B>(<?<MyValue>\d+.?\d*) USD</B>

--
Göran Andersson
_____
http://www.guffa.com
Apr 3 '07 #4
LEM,

Are you trying to get multiple instances of this pattern from one very
long string, or are you getting it string by string?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"LEM" <an*******@nospam.comwrote in message
news:eP**************@TK2MSFTNGP06.phx.gbl...
>
So do you suggest to go character by character until I find my pattern?
The text buffer can be very big.

Nicholas Paldino [.NET/C# MVP] wrote:
>LEM,

Why use a regular expression for this? You know that you will have
the string wrapped in <Band </B>, you also know there will be a space,
along with up to three characters after it. Everything else is a number.
It would be very easy to code this up without regular expressions.

Hope this helps.

Apr 3 '07 #5
<B>(?<value>[\d.]+)\s\w{3}</B>

Assuming that you want to capture only the number into a named capturing
group with name "value".

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"LEM" <an*******@nospam.comwrote in message
news:O5**************@TK2MSFTNGP02.phx.gbl...
Hi,

I'm trying to use Regex to find a string inside a text buffer.
I am trying to find this pattern:

<B>1.33594 VAL</B>

where 1.33594 is a number that may change. My problem is to find a
regular expression that can read that and extracts the number.

I have tried with the following but I don't get any matches back

string pattern = @"(<B>?<MyValueUSD</B>)";

Any ideas?

Thanks!

Apr 3 '07 #6
LEM

Thanks, Göran. I got it to work making a few modifications to
your example.

Regards

Göran Andersson wrote:
LEM wrote:
>Hi,

I'm trying to use Regex to find a string inside a text buffer.
I am trying to find this pattern:

<B>1.33594 VAL</B>

where 1.33594 is a number that may change. My problem is to find a
regular expression that can read that and extracts the number.

I have tried with the following but I don't get any matches back

string pattern = @"(<B>?<MyValueUSD</B>)";

Any ideas?

Thanks!

The ?<namepart is part of the (?<name>...) construction, and can't be
placed anywhere but directly after the starting parenthesis. It just
specifies the name of the group, and doesn't consume any characters in
the match, so you also have to specify a pattern for the digits.

Try this:

<B>(<?<MyValue>\d+.?\d*) USD</B>
Apr 3 '07 #7

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

Similar topics

5
by: Josip Maslaæ | last post by:
Hello. I'm stuck! :) I need a regular expr. that would match any expresion that doesn't start with some words (not letters - words!) For example - reg. expr. that matches any expression...
6
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? ...
0
by: Dean Householder | last post by:
------=_NextPart_000_02BD_01C34F8E.E3357E70 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Is it possible to run a query that will just alter text...
1
by: Daniel Suarez | last post by:
Hi there, I got the following expression in C#: string expresion = " 00.00% 00.00% 23.00% "; I want to split it out, with the following code: Regex regex...
5
by: Josema | last post by:
Hi to all, i did this regular expresion <!--!.*!--> that matchs all occurrences of type <!--!Name!--> <!--!Description!--> and so on... I would like to know the regular expression to get...
2
by: intrader | last post by:
I can't figure out why VS2005 has a problem with the following definition Regex rx = new Regex(@"('|\")"); //here put squiggle under "); what I think I am writing is a regular expresion...
7
by: PJ6 | last post by:
Is it possible for a regular expression to macth only an empty string? What I want is exactly {0}, but that causes the parser to throw an exception - parsing "{0}" - Quantifier {x,y} following...
6
by: Jeff | last post by:
I always have trouble with javascript regexes... I want to parse apart a string and remember the matches and use them elswhere. Say I have: var test_string='one_two-three'; In perl I...
2
by: sajancr | last post by:
dear sir, i need help in perl program where i want to search a string from paragraph and to convert all the letters in para to X except that string... in this program i have used string matching...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.