string searching??
-
I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!
Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!
-
I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!
Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!
Do the following, where 'keyword' is the search string (must have length of at least 2 characters)and 'str' is the file string:
bool inAsp = false;
bool inATag = false;
List matches = new List();
List curGuess = new List();
for (int i = 0; i < str.Length; ++i) {
char c = str.CharAt(i);
if (inAsp) {
if (EndingAspTag) // this is a pseudocode conditional
inAsp = false;
continue;
} else if (inATag) {
if (EndingATag) // this is a pseudocode conditional
inATag = false;
continue;
} else if (StartingAspTag) { // this is a pseudocode conditional
curGuess.Clear();
inAsp = true;
} else if (StartingATag) { // this is a pseudocode conditional
curGuess.Clear();
inATag = true;
}
for (int j = curGuess.Count - 1; j >= 0; --j) {
if (c != keyword.CharAt(++curGuess[j]))
curGuess.RemoveAt(j);
else if (curGuess[j] == keyword.Length - 1) {
matches.Add(i - curGuess[j]);
curGuess.RemoveAt(j);
}
}
if (c == keyword.CharAt(0))
curGuess.Add(0);
}
for (int i = 1; i < matches.Count; ++i) {
if (matches[i] - matches[i - 1] < keyword.Length)
matches.RemoveAt(i--);
}The code for the above conditions to check for entering or exiting an 'asp' or 'a' tag segment is non-trivial, as you also need to take into account whether you are within quotes, but you get the idea. This is also very inneficient, but it will work. Hope this helps,
-Jeff
-
I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!
Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!
Small Rat wrote:
I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this??
Have you attempted to solve the problem yourself? This site isn't for people who want their work done for them. There's plenty of resporces on Regular Expressions available on the web. Have you looked at any of them. BTW, I'm particularly surprised to see such behaviour from someone who claims to be Microsoft certified :suss:
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
-
I want get all the occurences for one string (e.g. keyword) in an ASP or html file. But I want to ignore some special html/asp tag that includes the searched string (in my case it is "keyword"). for example: 1) this is a test keyword string. (I want this) 2) <a href='#'>the is second keyword</a> (I don't want this) 2) <% 'this is keyword in asp code %> (I don't want this) I know regular express may solve this problem. But I don't know how?? Can somebody give me an example regular exression for this?? Thanks a lot!
Alan Shen MCAD for .NET Version ^~^~^~^~^~^~^~^~^~^~^ Great idea is the beginging of success!
Honestly. This is a C# forum. Do you really think you are going to get ASP help in this forum?
Deja View - the feeling that you've seen this post before.