|Do you know where your variables are?|
Regex Queryby DanielSpaniel (Scribe)
|on Aug 26, 2013 at 20:41 UTC||Need Help??|
DanielSpaniel has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to create what I thought should be a rather simple regex, but I seem to be having all kinds of problems with it (due in part, maybe, to an absence from Perl for a while)
Anyway, I'm trying to identify, and then alter, URLs in given strings. The URLs and the strings will vary daily, and in quality of formatting. The URLs could be anything at all, but they are just plain URLs (i.e. no HTML tags).
There may be more than one URL in a string, and the strings may contain both http and/or https URLs.
The URLs might be followed by any character, so it's not necessarily easy to figure that bit out. The character following the URL could just as easily be a misplaced quotation mark which doesn't even belong there, or it could be a space, or new line character, etc.
For example, a string might look like any of these (among other possibilities):
I've played with numerous variations of this regex, but the latest incarnation, which doesn't really work very well, is below:
As can be seen, I'm trying to create the proper anchor tags to go with the given URL in the string, to create a proper link. The regex above works for very simple examples, but nothing more complex. i.e. it would work on example (d) above, but nothing else.
Any assistance would be much appreciated!