Questions tagged [matchevaluator]

13 questions
57
votes
1 answer

How does MatchEvaluator in Regex.Replace work?

This is the input string 23x * y34x2. I want to insert " * " (star surrounded by whitespaces) after every number followed by letter, and after every letter followed by number. So my output string would look like this: 23 * x * y * 34 * x * 2. This…
dontoo
  • 793
  • 1
  • 6
  • 10
29
votes
4 answers

What is the equivalent of Regex-replace-with-function-evaluation in Java 7?

I'm looking for a very simple way of getting the equivalent of something like the following JavaScript code. That is, for each match I would like to call a certain transformation function and use the result as the replacement value. var res = "Hello…
user2864740
  • 60,010
  • 15
  • 145
  • 220
28
votes
2 answers

How would I pass additional parameters to MatchEvaluator

I have a bit of code that looks like this: text = reg.Replace(text, new MatchEvaluator(MatchEvalStuff)); I need to pass in a 2nd parameter like this: text = reg.Replace(text, new MatchEvaluator(MatchEvalStuff, otherData)); Is this possible, and…
Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168
8
votes
3 answers

What does this "Lambda Expression" do?

Just come across the following line of code and having a hard time finding documentation for it, is it a lambda expression? What does this do? temp = Regex.Replace(url, REGEX_COOKIE_REPLACE,match =>…
m.edmondson
  • 30,382
  • 27
  • 123
  • 206
5
votes
3 answers

How do you use Regular Expressions to replace a particular match (e.g "last" or "second to last")?

I am trying to replace a single (last or next-to-last) match in a string. I have my Regular Expression already and it works, but it replaces ALL items, then I have to run back through and replace a single item. Regex.Replace(BaseString,…
jeffreypriebe
  • 2,267
  • 25
  • 30
2
votes
1 answer

How to include separators in the regex match result?

Currently, I am doing search and replace using this pattern: "(?<=\\{).+?(?=\\})". This finds everything inside curly brackets. (Courtesy of https://stackoverflow.com/a/8526268/1143917) I use 'MatchEvaluator' with a delegate, so, when the input…
Vlad
  • 2,475
  • 21
  • 32
2
votes
3 answers

How to replace each Capture of a Group individually?

I have a regular expression which uses GroupCollections in it's capture to capture a group of Item Id's (which can be comma separated, also accounting for the final one to have the word 'and'): (\bItem…
michael
  • 14,844
  • 28
  • 89
  • 177
1
vote
2 answers

The Unknown Exception DateTime C#

The data that I am sending to convertStringToDataSet function is \r\n \r\n Doe,JaneN\r\n 175\r\n …
Sandhurst
1
vote
1 answer

Custom function on Regex replace in Java

I need to replace all words in a text by applying a specific replacement method Modify(). I have the following code snippet in C#: Regex regex = new Regex("[A-Za-z][a-z]*"); regex.Replace(text, x => Modify(x.Value)); The Modify() function is some…
Igor Ševo
  • 5,459
  • 3
  • 35
  • 80
0
votes
1 answer

Return an out parameter value from the method called by the MatchEvaluator delegate?

I have existing methods that each returns a String type. And now, I need to return additional value from a method and pass it to the other. I found out that one way to do this is to use the "out parameter". The value (paramObject) that I want to…
klee
  • 15
  • 1
  • 5
0
votes
1 answer

regex replace matches with function and delete other matches

I have a string like the one below and I want to replace the FieldNN instances with the ouput from a function. So far I have been able to replace the NN instances with the output from the function. But I am not sure how I can delete the static…
hairyone
  • 439
  • 1
  • 5
  • 16
0
votes
2 answers

RegEx for ranges

I want to be able to use a RegEx to parse out ranges like a Windows Print dialog (such as 1-50,100-110,111,112). The following is my current code and I am not clear on how to parse for the additional commas and numbers. I can parse out the hyphen,…
user195488
-2
votes
1 answer

MatchEvaluator gives "Cannot use a lambda expression..." error

I'm modifying the contents of several files. I have this Regex in a form and it's called directly from a button's click event. public partial class MainForm : Form { private void UpdateButton_Click(object sender, EventArgs e) { //…
akinuri
  • 10,690
  • 10
  • 65
  • 102