473,385 Members | 1,863 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 do I pass * characters in System.Text.RegularExpressions.Regex.Replace

15
I am using System.Text.RegularExpressions.Regex.Replace(input , pattern, replacement, options) in c# to replace the input string. The pattern I am using may have one or more * or . or any other character basically inside mixed in with the rest of the string. I want to find this string in the input and replace it with something.

For example say my string is *000000000

I get the following error
System.ArgumentException: parsing "*000000000" - Quantifier {x,y} following nothing.

How do I treat the * as a regular character?

I tried replacing all instances of the * character with \* before passing it to replace function but in the final output I have the \ characters along with it...I do not want that.

Thanks in advance for any help
Nov 23 '10 #1
1 3492
Sal Sal
15
actually I found something that works

I used Regex.Escape(pattern) to treat the * as a regular character. I pass that instead of pattern itself in the replace function.
Nov 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ian Payne | last post by:
Documentation says it does: Quickwatch lists it (but <cannot view indexed property> as expected) So how come the compiler throws an error? I can of course work round it (in C#) with myMatches,...
2
by: Juan | last post by:
Hi, I´m using System.Text.RegularExpressions, I want to find any acurrence of the char & or % or | Ehat is the correct sintax for the Match method? This is what I´m usinf but is not working:...
2
by: Doug | last post by:
I'm a little confused by this functionality. It doesn't seem to be behaving like it should. I am using the following regular expression to validate email addresses:...
8
by: Richard Lionheart | last post by:
Hi All, I tried using RegEx, but the compiler barfed with "The type of namespace 'RegEx' could not be found. Prior to this, I had the same problem with MatchCollection, but discovered it's...
2
by: chris fink | last post by:
Using regular expression testers such as Expresso or Dan Appleman's tester, I have a regular expression that tests fine and is returning matches. However, when the same regex is run through code,...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
0
by: Vikram | last post by:
I am using regex class in codebehind to validate some control's text. But for checking , postback is done.I want to avoid postback and check the same exprseeion using regularexpressionvalidator. I...
5
by: cj | last post by:
I just ran across this in the VB help. Sounds perfect. Only they don't tell me what namespace must be imported to use regex. I guess that's the problem cause I pasted this into a test program...
3
by: Curious | last post by:
I have another question about Regular Expression. If I use: if (temp.Contains("Ending") == true) { temp = System.Text.RegularExpressions.Regex.Replace(temp, "Ending", "Beginning"); } It...
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
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...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.