tags:

views:

31

answers:

3

Is there a way to select all <br> tags that follow a paragraph with a given class? i.e. <p class="myclass">This is a paragraph</p><br>

There may be other <br> in the HTML so I cannot use this:

br {display:none;} 

and I cannot delete all <br> tags. If there is a way to select these particular <br> tags then I can use CSS.

There are about 700 pages and I do not want to go through each of them to make sure if the <br> is needed or not. I do know that it is not needed following a paragraph with the class of "myclass".

If there is no way to select these tags then I think that I can use BBEdit to do the search and replace using a regular expression. But I don't know how to write the RE that would work.

TIA, Linda

+2  A: 
p.myClass+br {display:none;}

This will select all <br> elements that are directly adjacent to a <p class="myClass"> element. If you need anything more dynamic than that, you will need regex.

Moses
A: 

Assuming BBEdit is similar to TextWrangler, you could use the built in Find dialogue.

Go to Search > Find... (Command + F), do "Seach For" </p><br> and "Replace With" </p> and then use the "Multi-file search" option at the bottom of the window to choose your files.

This isn't a regex, but since you said you're using BBEdit, which is made by Bare Bones and supposedly shares a lot with TextWrangler, it should work. (Otherwise just download TW for free). It even gives you a nice pop-up telling you what it found and replaced in case you want to review, etc.

See this page for more info on BBEdit's search and other fun features.

nearlymonolith
A: 

Supposing you want to use regex to delete all <br> tags that follow a paragraph with a class named myclass:

Search for: (<p\b[^><]\sclass\s=\s*["']?myclass["']?[^><]>.?<\/p>\s*)<br\s*/?>

Replace with: $1

Note, you must ensure that all p tags in your HTML documents are properly closed.

Vantomex