Solved

Regular expression to exclude HTML tags from text replacement

Posted on 2004-09-28
7
536 Views
Last Modified: 2011-09-20
i need to create a regular expression (in Java) to replace sections of text that are NOT in <span> HTML tags. basically i am replacing a set of terms with a block of text inside span tags, but i don't want the terms inside those blocks of text to be matched as well. so i only want to replace terms that aren't inside <span> tags.

My regular expression so far is:

((<span.*/span>)*^(<span)) ($term)

where $term is the term that i want to replace. basically the regular expression needs to say "search for all instances of $term that are not between an open and end <span> tag (and replace with the defined text)".

please ask if i haven't explained this adequately and i can explain the situation more clearly.

any help would be appreciated,

Stafford

p.s. i'm not all that good at Regular Expressions, so please excuse the one above ;)
0
Comment
Question by:staffordvaughan
  • 3
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
Comment Utility
Regular expressions are not particularly good for *not* matching things. What i'd suggest is the something like the following:

final String RE_ANY_TAG = "(<[A-Za-z\\-]+>)([^<]+)(<[/A-Za-z\\-]+>)";

then check the first group does *not* contain "<span>"

0
 

Author Comment

by:staffordvaughan
Comment Utility
thanks for your response, but can you be more specific please?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:staffordvaughan
Comment Utility
the question is still open, i would like for someone who is good at regular expressions to actually post the regular expression solution if possible. i'm familiar with regular expressions in general, but the actual solution to this question is eluding me.

or perhaps suggest a more appropriate category to post this question on? i could not find a better one than this.

thanks
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>to actually post the regular expression solution if possible

That's quite a bit of work! What are talking about specifically here:

>>
basically i am replacing a set of terms with a block of text inside span tags, but i don't want the terms inside those blocks of text to be matched as well. so i only want to replace terms that aren't inside <span> tags.
>>
0
 

Author Comment

by:staffordvaughan
Comment Utility
i accepted the first response as the answer even though it wasn't really what i was after. as you say though, the specific regular expression is probably a lot of work and my explanation might not have been sufficient. thanks for your help anyway, as it turned out i used a different (non regular expression) method for doing the task because i just couldn't work out the regular expression.

thanks,
Stafford
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now