‎2016 Feb 02 1:59 PM
Hello,
I am working with regular expressions and I am looking for some help.
All the URLs are enclosed within "[[" and "]]".
I am able to read the URL if a single URL occurs in a line.
However I get an undesirable result when there is more than one URL in the same line or when a single URL spans over multiple lines.
As you can see from the image the 2nd line includes "and". I must get 2 URLs from this line instead one 1.
The URL in the 4th line spans over multiple lines and is not read.
What would be the right REGEX for the desirable result?
Any help/suggestion is welcome.
Thanks and regards,
Pranay D.
‎2016 Feb 02 4:21 PM
Hi,
you want to find any character but "]]" after "[[".
You can use \[\[[a-z./:]*\]\].
Means search for [[ then for any character or dot or / or :.
Finally comes closing ]].
Line break may be something like \r\n.
Regards
Chris
‎2016 Feb 02 2:19 PM
‎2016 Feb 02 4:21 PM
Hi,
you want to find any character but "]]" after "[[".
You can use \[\[[a-z./:]*\]\].
Means search for [[ then for any character or dot or / or :.
Finally comes closing ]].
Line break may be something like \r\n.
Regards
Chris
‎2016 Feb 03 5:22 AM
Hi Chris,
Thank you for your timely reply.
Your REGEX works fine when for the 2nd line.
I assumed it had to do something with the greediness of the REGEX.
However, when the URL spans over multiple lines it still doesn't match.
Regards,
Pranay D.
‎2016 Feb 02 4:38 PM
If there is at least one space between the ending brackets ]] and opening brackets [[ then you can use the following regular expression: \[\[[^\s]+\]\]
I don't know how to achieve the scenario where the text spans multiple lines.
-Chandra
‎2016 Feb 02 4:48 PM
You can use the one Christian mentioned but you need to expand the expression.
For eg: if the url contains numbers and Capital letters [[https://www.google.com/example9]] then you should have one of the following
\[\[[a-zA-Z0-9./:]*\]\] (if you respect the case)
\[\[[a-z0-9./:]*\]\] (if you ignore the case)
‎2016 Feb 03 5:29 AM
Hi Chandra,
Yeah, there is a possibility that the URL is entered after a space.
And I am ignoring the case, so Christian's REGEX should work fine.
Thanks for pointing that out!
However I still haven't found anything on URL spanning over multiple lines.
Regards,
Pranay D.
‎2016 Feb 02 4:43 PM
Ironic this thread showed up for me today. I have been doing so many regular expressions lately, I think I have nightmares about them (ie. "solve this regular expression so you can go to sleep" kind! haha). I have almost memorized this page...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
LOTS of regex generators out on the web too to help you.....and saved you from nightmares.
‎2016 Feb 02 4:49 PM
I have this: http://www.regexr.com/#
And
Regex Tester - Javascript, PCRE, PHP
In my favourites.
Another good source is
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
‎2016 Feb 03 5:43 AM
Thank you for the helpful links.
I'm just starting with Regular Expressions and I hope going through these links will help me avoid the nightmares.
Thanks and regards,
Pranay D.
‎2016 Feb 02 9:39 PM
Depends on how you want to vallidate the url:
If you want to catch only the characters between the brackets and not validate them, I would recommend the regex:
\[\[[^\]]+\]\]
[^\]]+ is a sequence of any characters except the ]. If you parenthise this string you can get all desired results into a internal table for example with:
FIND ALL OCCURRENCES OF REGEX '\[\[([^\]]+)\]\]'
IN 'your string with the [[url]]'
RESULTS lt_result.
Hope it helps, Andreas
‎2016 Feb 03 5:35 AM
Hi Andreas,
I don't have to validate the URLs within the brackets.
Your REGEX works fine for the first and second scenario, however it doesn't match URLs that span over multiple lines.
Regards,
Pranay D.
‎2016 Feb 03 6:07 AM
Hi Pranay,
concatenate multiple lines to one string ...
Regards,
Klaus
‎2016 Feb 03 7:09 AM
While we use regex in ABAP, I don't think this is the best place to ask questions about forming regex. I suggest stack overflow or the like as a better place.
Anyway, there's plenty of information in this thread now, so I think it should be closed.