Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Try as I might, I cannot find an expression to match one or more spaces in the Visual Studio 2012 Find and Replace dialog. I am trying to match expressions like the following:

<p class="StyleA">Chapter 12</p>


The expression is completely constant except for two things:

1. There may be more than a single space between 'Chapter' and the number that follows it.
2. Obviously the chapter number changes, using any sequence of numeric characters [0-9].

My latest attempts are as follows, but both match only as far as the end of the word 'Chapter'.

<p class="StyleA">Chapter[^<]+</p>

<p class="StyleA">Chapter[ ]+</p>


Can anyone see where I am going wrong, please?


Kind wishes ~ Patrick
Posted

1 solution

The problem is that you only match p-tags containing Chapter followed by some spaces, without the number. Try this instead:
HTML
<p class="StyleA">Chapter +\d+</p>

Also, it's not necessary to put the space into a character class.

If you don't only want to match spaces, but all whitespace, then replace the space with \s
HTML
<p class="StyleA">Chapter\s+\d+</p>
 
Share this answer
 
Comments
Patrick Skelton 28-Apr-14 4:45am    
Yes, that works fine. I did actually have the number recogniser in my code, but I failed to include it in my question. Sorry. It was the space thing that was causing me problems, though, so thank you.
Thomas Daniels 28-Apr-14 12:04pm    
You're welcome!

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