Replace all instances of an HTML tag within another
Moderators: AmigoJack, bbadmin, helios, MudGuard
-
bzz bzz
- Posts: 6
- Joined: Fri Jul 04, 2008 2:28 pm
Replace all instances of an HTML tag within another
Hello all, v. impressed with your expertise in these forums. I wonder if you can help?
(Meaning, "this may be obvious to some of you, be gentle with me")
I'm looking to replace some stray HTML bold tagging that's shown up in an XML archive. So I need to remove all instances of <b> or </b>, BUT only if it occurs within the title element <atl></atl>. I need to preserve the tagging if it occurs in other elements.
Suspect that TextPad can't "find all" within an expression, and that WildEdit may have something to offer.
Also I got stuck trying to use the alternative expression (pipe).
Any helpful feedback appreciated. Thanks
(Meaning, "this may be obvious to some of you, be gentle with me")
I'm looking to replace some stray HTML bold tagging that's shown up in an XML archive. So I need to remove all instances of <b> or </b>, BUT only if it occurs within the title element <atl></atl>. I need to preserve the tagging if it occurs in other elements.
Suspect that TextPad can't "find all" within an expression, and that WildEdit may have something to offer.
Also I got stuck trying to use the alternative expression (pipe).
Any helpful feedback appreciated. Thanks
-
gan
If it's all on a single line or the number of lines between <atl> and </atl> is always the same it's easy, but if the <atl></atl> span several lines which might differ it might be hard using regex.....in that case you at least have to run search&replace several times. So let me know if the number of lines is always the same or not/if it's always on the same line and i can give you some examples.
-
gan
Maybe it's a bit harder then i first thought to make it perfect:) But i'm sure it should be possible to find a working solution. The best way to do it depend how the lines look like.
Is there some lines that contain several "<atl>somthing</atl>" on the same line? Like this:
Or is there only a single <atl></atl> on each line?
Is there some lines where there might be many <b></b> inside a single <atl></atl> like this example:
Is there some lines that contain several "<atl>somthing</atl>" on the same line? Like this:
Code: Select all
<atl>some <b>text</b></atl><atl>some <b>more</b> text</atl>Is there some lines where there might be many <b></b> inside a single <atl></atl> like this example:
Code: Select all
<atl>this <b>is</b> some <b>test</b></atl>-
bzz bzz
- Posts: 6
- Joined: Fri Jul 04, 2008 2:28 pm
Hi,
The second example is true: there is one instance of <atl></atl> in each document and there may be zero or more instances of bold markup within:
The second example is true: there is one instance of <atl></atl> in each document and there may be zero or more instances of bold markup within:
Code: Select all
<atl>this <b>is</b> some <b>test</b></atl>
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
This works for no bold tags or one set of bold tags:
Search for: <atl>(.*)<b>(.*)</b>(.*)</atl>
Replace with: <atl>\1\2\3</atl>
It will also work for multiple sets of bold tags, but you need to do multiple passes.
Did a test on this:
<atl>this is some test</atl>
<atl>this <b>is</b> some test</atl>
<atl>this is some <b>test</b></atl>
<atl>this <b>is</b> some <b>test</b></atl>
Result was this, after two passes:
<atl>this is some test</atl>
<atl>this is some test</atl>
<atl>this is some test</atl>
<atl>this is some test</atl>
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Search for: <atl>(.*)<b>(.*)</b>(.*)</atl>
Replace with: <atl>\1\2\3</atl>
It will also work for multiple sets of bold tags, but you need to do multiple passes.
Did a test on this:
<atl>this is some test</atl>
<atl>this <b>is</b> some test</atl>
<atl>this is some <b>test</b></atl>
<atl>this <b>is</b> some <b>test</b></atl>
Result was this, after two passes:
<atl>this is some test</atl>
<atl>this is some test</atl>
<atl>this is some test</atl>
<atl>this is some test</atl>
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Hope this was helpful.............good luck,
Bob
Bob
-
bzz bzz
- Posts: 6
- Joined: Fri Jul 04, 2008 2:28 pm
Thanks for this, much appreciated.
Tinkering with the expression, I was able to run a FIND along these lines:
And this is about the limit of my expertise - I can't see a way to number these instances of bold, then replace with \1\2\3 etc.
If the RegExp alone can't strip out these tags within a known string, I can at least identify the files where it occurs, and go from there.
Cheers everyone
Tinkering with the expression, I was able to run a FIND along these lines:
Code: Select all
<atl>(.*)[<b>[^^]*</b>]*(.*)</atl>If the RegExp alone can't strip out these tags within a known string, I can at least identify the files where it occurs, and go from there.
Cheers everyone
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact: