Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding using Regex.pls help

Status
Not open for further replies.

RakhiKalra

Programmer
Jun 6, 2003
41
0
0
IN
Hi,

I am building a facility to search site contents utility which searches the specified text on the other pages of the same site and gives the list of all pages where it has found the search text.

the search is being done properly.but there is one case in which i am getting an error, when i am entering "*" (an asterisk) in the search text box.error is the following:-


System.ArgumentException: parsing "*" - Quantifier {x,y} following nothing. Parameter name: *


the code comes here

public void SearchWords(string SearchWords)
{
int intCounter,intLocation;
string[] strSearchWords;
MatchCollection mcMatchCollection;
string strLeft,strContents;
try
{
strSearchWords = SearchWords.Split(' ');
for(intCounter=0;intCounter<strSearchWords.Length;intCounter++)
{
//error comes on the following statement
mcMatchCollection = Regex.Matches(Contents,strSearchWords[intCounter],RegexOptions.IgnorePatternWhitespace);
if(mcMatchCollection.Count>0)
{
MatchCount=mcMatchCollection.Count;
strLeft=Contents.Substring(0,mcMatchCollection[0].Index);
intLocation=strLeft.LastIndexOf(".");
if(intLocation==-1)
intLocation=0;
else
intLocation++;
strContents=Contents.Substring(intLocation,Contents.Length-intLocation);
if(strContents.Length>500)
Description=strContents.Substring(0,500);
else
Description=strContents;
}

}
}
catch(Exception objException)
{
throw new Exception(objException.Message,objException);
}
}
#endregion




Rakhi
 
The asterix is a character in regular expressions (along with ($ ^ { [ ( | ) ] } * + ? \)

You should escape the required items in the search word using the syntax \*

Regards,

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top