473,503 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegularExpression for finding word

Joe
I have an expression where I need to replace words with values (#'s).

Take the following expression:

val1 *2/( val3 + val4*12/val1)

Given this example how could I replace val1 with the number 15?
Note: the spacing in the above expression was intentional. There may or may
not be spaces between the variables and the operators but there can NOT be
no space between a variable name and a literal value;
Nov 16 '05 #1
3 1029
"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in
news:uQ*************@TK2MSFTNGP12.phx.gbl...
I have an expression where I need to replace words with values (#'s).

Take the following expression:

val1 *2/( val3 + val4*12/val1)

Given this example how could I replace val1 with the number 15?
Note: the spacing in the above expression was intentional. There may or
may
not be spaces between the variables and the operators but there can NOT be
no space between a variable name and a literal value;


Have you tried "\bval1\b"? That's supposed to match only "whole word"
val1's.

Niki
Nov 16 '05 #2
Joe
Thanks.

"Niki Estner" <ni*********@cube.net> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in
news:uQ*************@TK2MSFTNGP12.phx.gbl...
I have an expression where I need to replace words with values (#'s).

Take the following expression:

val1 *2/( val3 + val4*12/val1)

Given this example how could I replace val1 with the number 15?
Note: the spacing in the above expression was intentional. There may or
may
not be spaces between the variables and the operators but there can NOT be no space between a variable name and a literal value;


Have you tried "\bval1\b"? That's supposed to match only "whole word"
val1's.

Niki

Nov 16 '05 #3

If you are doing a simple replace like this then using String.Replace would
be faster.

Dim formula as String = "val1 *2/( val3 + val4*12/val1)"
Dim value as Double = 15
formula = formula.Replace("val1", value.ToString())

Else you would use the pattern
val(\d+)
to match your value place holders. This puts the value index in group 1
(Match.Groups(1)) so you know what number to replace the value by.

Robby

"Joe" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:uQ*************@TK2MSFTNGP12.phx.gbl...
I have an expression where I need to replace words with values (#'s).

Take the following expression:

val1 *2/( val3 + val4*12/val1)

Given this example how could I replace val1 with the number 15?
Note: the spacing in the above expression was intentional. There may or
may
not be spaces between the variables and the operators but there can NOT be
no space between a variable name and a literal value;

Nov 16 '05 #4

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

Similar topics

3
13766
by: Noam Dekers | last post by:
Hi all, I would like to find a word stored in a text file. Structure: I have one file named keyWords.txt that stores some key words I'm interested in finding. In addition I also have a file...
2
2970
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
2
9075
by: Stephan Bour | last post by:
Follow up to previous question: I¹m trying to validate a multipline asp text box that can have a maximum of 150 word characters but any number of white space, carriage returns or tabs. I tried...
2
2719
by: John Hoge | last post by:
I have a regex "^\d{5}$" that does not allow blanks, but the RegularExpressionValidator does not fire for empty fields. Is there a way to make it do so? I would rather not include a separate...
2
2835
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
3
1731
by: Arpan | last post by:
Consider the following code which validates a TextBox using RegularExpression: <form id="form1" runat="server"> <asp:TextBox id="txt1" runat="server"/> <asp:RegularExpressionValidator...
1
1521
by: Arpan | last post by:
Using RegularExpression, I want to validate a TextBox so that the TextBox accepts only 8-digit numbers. This can be done with the following RegularExpression: {8} But how do I validate the...
1
2016
by: prp | last post by:
hi all, I have a problem.Suppose I use a regularexpression validator for zip code. An User fill wrong entry in the relevant textbox then regularexpression validator fires.but user did not...
1
1345
by: avik1612 | last post by:
Hi, I have created a program to find text files in a particular directory or folder. and to find a particular word in that files i finding it difficult to put the list in an array and finding...
0
7202
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
7278
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
7328
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...
1
6991
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
7458
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
5578
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
5013
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
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.