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

How to modify the value of a named capture before doing a replace?

Hello,

I have a regex and I want to modify the value of a named capture
before doing the regex.Replace.

So something like:

string text = Regex.Replace(oldText, myRegex, @"<a href="$1">$1</a>",
regexOptions);
Now I want to modify the value of the second $1 just in case it is too
long to display.

This doesn't work, but this is what I want to do somehow!

string text = Regex.Replace(oldText, myRegex,
String.Format(@"<a href="$1">{0}</a>",
MyFunction("$1")),
regexOptions);
Apr 10 '08 #1
2 1273
Try:

string text = Regex.Replace(oldText, myRegex, delegate (Match
match) {
string capture1 = match.Captures[0].Value;
return string.Format(@"<a href=""{0}"">{1}</a>",
capture1, MyFunction(capture1));
}, regexOptions);

Marc
Apr 10 '08 #2
On Apr 10, 5:26 pm, Marc Gravell <marc.grav...@gmail.comwrote:
Try:

string text = Regex.Replace(oldText, myRegex, delegate (Match
match) {
string capture1 = match.Captures[0].Value;
return string.Format(@"<a href=""{0}"">{1}</a>",
capture1, MyFunction(capture1));
}, regexOptions);

Marc
Marc, it didn't compile for some reason (i.e. there is not method that
takes in a delegate?)
Jun 27 '08 #3

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

Similar topics

9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
0
by: karenmiddleol | last post by:
The following code works fine I can connect to a SQL database and list all the records in the Orders table onto a web page. Now our users want me to modify it so that each row displayed as a...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
4
by: c++ newbie | last post by:
hello gurus of C++ programming, I am a student doing my masters in computer applications.I am a bit experienced in VB 6.0.I am currently doing a project in vb 6. To accompish a certain task I...
1
by: cuj0 | last post by:
Don't ask me why, but I have a situation where a "<base href="..." value has been set for all my pages, but under certain situations I don't want it to have an effect. Therefore, I was hoping that...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
10
by: Phil Latio | last post by:
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I...
6
by: Ramesh | last post by:
Hello, I am using the ofstream class to create a text file with keys and values like: Key1=Value10 Key2=Value15 Key3=Value20 In case I need to set a new value for Key2, say value50 - I am...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.