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

string replacement - regex?

Art
Hi & help,

I'm trying to parse arithmetic expressions such as 4*(7-2.1).

The first thing I'm trying is to add spaces to get: 4 * ( 7 - 2.1 ).

I thought that Regular Expressions would be the way to go. I tried:
regex.replace("\D", " \D ") which did not work. I don't know how to refer
to the string that was matched in forming the replacement.

Also, I tried regex.replace("+*", " +* ") This was even worse because I'm
apparently not using a recognizable syntax.

Did I mention that this is my first attempt at regular expressions?

I'd really appreciate any suggestions.

Art
Nov 21 '05 #1
2 1272
In order to use "tagged expressions", you need to use the following format.
I am not too awful good with regex either, but there is a good tool called
Regex Builder that I always use to help out with my Regular Expressions.
So, in short, I cant help you with your problem necessarily, but the Tagged
expression format is as follows...
regex.replace("\D", " \D ")

to

regex.replace("{\D}", " \1 ")

"Art" <Ar*@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi & help,

I'm trying to parse arithmetic expressions such as 4*(7-2.1).

The first thing I'm trying is to add spaces to get: 4 * ( 7 - 2.1 ).

I thought that Regular Expressions would be the way to go. I tried:
regex.replace("\D", " \D ") which did not work. I don't know how to
refer
to the string that was matched in forming the replacement.

Also, I tried regex.replace("+*", " +* ") This was even worse because I'm
apparently not using a recognizable syntax.

Did I mention that this is my first attempt at regular expressions?

I'd really appreciate any suggestions.

Art

Nov 21 '05 #2
Art
Thanks Rick -- I will give that a try.

Art

"Rick Mogstad" wrote:
In order to use "tagged expressions", you need to use the following format.
I am not too awful good with regex either, but there is a good tool called
Regex Builder that I always use to help out with my Regular Expressions.
So, in short, I cant help you with your problem necessarily, but the Tagged
expression format is as follows...
regex.replace("\D", " \D ")

to

regex.replace("{\D}", " \1 ")

"Art" <Ar*@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi & help,

I'm trying to parse arithmetic expressions such as 4*(7-2.1).

The first thing I'm trying is to add spaces to get: 4 * ( 7 - 2.1 ).

I thought that Regular Expressions would be the way to go. I tried:
regex.replace("\D", " \D ") which did not work. I don't know how to
refer
to the string that was matched in forming the replacement.

Also, I tried regex.replace("+*", " +* ") This was even worse because I'm
apparently not using a recognizable syntax.

Did I mention that this is my first attempt at regular expressions?

I'd really appreciate any suggestions.

Art


Nov 21 '05 #3

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

Similar topics

4
by: andrewflanders | last post by:
I have an associative array of keys and values. I want to search a string for the existance of keys and replace them with the values in the array. The problem is that some of the keys resemble...
7
by: VMI | last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I cannot use the String.Replace() fuction. It has to be by replacing one char with another. Thanks.
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
21
by: gary | last post by:
How would one make the ECMA-262 String.replace method work with a string literal? For example, if my string was "HELLO" how would I make it work in this instance. Please note my square...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
5
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h>...
4
by: Phil Sandler | last post by:
Hello, What is the fastest/most efficient way of doing string replacement in csharp/.net? An example would be: "Hello, my name is {FirstName}, and I live in the town of {City} with my wife...
5
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of...
7
by: Tom de Neef | last post by:
I need to change one character at a known position in a string. In Pascal I would change the P's character of a string S into 'x' with S:='x'; In JavaScript I come no further than S =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.