Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regular Expression

Posted on 2004-04-14
7
Medium Priority
?
347 Views
Last Modified: 2010-04-17
I'm trying to develop a regular expression to match a space character in a block of code, but it can't
be contained within a hyperlink.

-------------------------
<a href="http://somwhere.com">This is the link, but I don't want any match in here.</a>  But any space
after this would be OK.  There also may not be any hyperlink in the text, in which case the first space found would be great.
-------------------------

In the above code, I would want the position of the first space after the closing </a>  If there was no hyperlink, then I would want the position of the first space in the paragraph.  I've been working on regular expression stuff for a couple of weeks but don't have any clue how to go about this.

Any tips?
0
Comment
Question by:vision69
  • 3
7 Comments
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 10821062
It would be great if you explain wxactly what are you trying to do. Why you need position of first space - probbaly you want to insert something there or get text before and after it.
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 10821073
Probbaly this is waht you need

\(?:<a.*<\/a>)( )\im
0
 

Author Comment

by:vision69
ID: 10821625
I have a piece of software that breaks up a block of text into pieces.  I want to insert (at random) a URL in the block of text.  But I don't want to accidently insert a hyperlink, inside another hyperlink...  That is why I'm looking for the first occurance of a space that is not inside an already existing hyperlink.
0
 
LVL 6

Accepted Solution

by:
BAlexandrov earned 1000 total points
ID: 10821937
I do not know how you will find a random place -this is your part.

If it was ASP with Javascript then this will do it - get first and third match and insert something between them

<%@ Language=JScript %>
<%
var reg  = /(<a.*<\/a>)( )(.*)/im
var text = "<a href=\"http://somwhere.com\">This is the link, but I don't want any match in here.</a>  But any space after this would be OK."
Response.Write (text.replace(reg,"$1new text$3"));
%>


0
 
LVL 10

Assisted Solution

by:Kavar
Kavar earned 1000 total points
ID: 10823195
/(<a[^xfe]*a\>)*?(/s)/im
$2 will be the white space

if you want to accomodate both then
/((<a[^xfe]*a\>)*?(/s)|(/s))/im



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

926 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