473,320 Members | 2,003 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.

regular expersion. replace all except those that matches the patte

hi,

i have a regular expression question here.

string: "({WBC} * {FBC} - {ABC} * 5)"
pattern: "(.*?)(\{)(.+?)(\})(.*?)"
replace: "$3 "

expected result: "WBC FBC ABC"
returned result: "WBC FBC ABC * 5)"

where did i go wrong?

any help will be much appreciated.

thanks!
Lance

Jul 21 '05 #1
2 1291
"Lance Koh" <La******@discussions.microsoft.com> wrote in
news:35**********************************@microsof t.com...
hi,

i have a regular expression question here.

string: "({WBC} * {FBC} - {ABC} * 5)"
pattern: "(.*?)(\{)(.+?)(\})(.*?)"
replace: "$3 "
".*?" at the end of the pattern will always match 0 characters - that's why
it's called "lazy".
expected result: "WBC FBC ABC"
returned result: "WBC FBC ABC * 5)"


As expected: " * 5)" is never matched, and never replaced.

Try something like: ".*?\{(.+?)\}[^{]*", replace with "$1 ".

Niki
Jul 21 '05 #2
as suggested, i tried ".*?\{(.+?)\}[^\{]*" and it worked. many thanks!

lance

"Niki Estner" wrote:
"Lance Koh" <La******@discussions.microsoft.com> wrote in
news:35**********************************@microsof t.com...
hi,

i have a regular expression question here.

string: "({WBC} * {FBC} - {ABC} * 5)"
pattern: "(.*?)(\{)(.+?)(\})(.*?)"
replace: "$3 "


".*?" at the end of the pattern will always match 0 characters - that's why
it's called "lazy".
expected result: "WBC FBC ABC"
returned result: "WBC FBC ABC * 5)"


As expected: " * 5)" is never matched, and never replaced.

Try something like: ".*?\{(.+?)\}[^{]*", replace with "$1 ".

Niki

Jul 21 '05 #3

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
26
by: Shannon Jacobs | last post by:
Sorry to ask what is surely a trivial question. Also sorry that I don't have my current code version on hand, but... Anyway, must be some problem with trying to do the negative. It seems like I get...
3
by: Derek Stone | last post by:
In my continuing inability to completely understand regular expressions I have a new one for you. I'd like to capture a string "A" unless it is anywhere in between string "B" and string "C". ...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
1
by: Stephajn Craig | last post by:
I'm working for the first time with Regular Expressions. I'm trying to return a match only when the word I'm looking for is on its own without any characters before or after it except for...
0
by: Lance Koh | last post by:
hi, i have a regular expression question here. string: "({WBC} * {FBC} - {ABC} * 5)" pattern: "(.*?)(\{)(.+?)(\})(.*?)" replace: "$3 " expected result: "WBC FBC ABC" returned result: "WBC...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Chris | last post by:
Hi everyone, I'm trying to parse through the contents of some text files with regular expressions, but am new to regular expressions and how to use them in VB.net. I'm pretty sure that the...
5
by: Tom | last post by:
- matches "a", "b", or "c" - matches anything except "a", "b", and "c" (abc) - matches "abc", with back reference ??? - matches anything except "abc" literally?? What is the syntax for this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: 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: 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.