vision69
asked on
Regular Expression
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?
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?
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.
Probbaly this is waht you need
\(?:<a.*<\/a>)( )\im
\(?:<a.*<\/a>)( )\im
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.