Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular Expression

Posted on 2004-04-14
7
Medium Priority
?
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

722 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