Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello ,
i am running a regex that searches an xml document for a certain tag and then replaces all its contents i.e. children/values tags.
i use this regex :
<(Car)>((\s)*(.)*)*</Car>

what could be the problem ?

I am using :
XML
Regex Car = new Regex (@"<(Car)>((\s)*(.)*)*</Car>");
  
Car.IsMatch (InputCarprofile)


The latter is taking lots of time.
Posted
Updated 13-Oct-10 21:55pm
v2
Comments
LittleYellowBird 14-Oct-10 3:40am    
Hi, you have asked for a solution but you haven't explained what the problem is. Do you get an error? What goes wrong? :)
OriginalGriff 14-Oct-10 3:47am    
How are you using it?
Edit your question and show the relevant code, please, with a small sample of your input XML and what you expect produced.
SuperAdministrator 14-Oct-10 3:55am    
Now ?
OriginalGriff 14-Oct-10 4:23am    
How big is InputCarProfile, and what does the data look like?
SuperAdministrator 14-Oct-10 4:25am    
about 50 - 60 lines of xml , where the car tag is approx 20-30 lines.

1 solution

This regular expression has several flaws:
1) looks to my that it has too many groups: (...)
2) too many * that lead to an exhautiive search (n-square of the document length?)
3) if it is multiline, the . will not match the end-of-line
4) there must be some non-greedy repetition, otherwise, you will finally match all from the first to the last entry at once (what is problably not what you want if you have more than one Car element.

For the simple IsMatch() call, the following is sufficient:

<Car>[\s\S]*?</Car>


Do I miss something?

Cheers

Andi
 
Share this answer
 
v2
Comments
SuperAdministrator 18-Oct-10 2:30am    
thanks ! it worked :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900