Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Regular expressions

pranaydubey
Explorer
0 Likes
4,297

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.

1 ACCEPTED SOLUTION
Read only

christian_lutter
Product and Topic Expert
Product and Topic Expert
0 Likes
3,470

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

13 REPLIES 13
Read only

Former Member
0 Likes
3,470
Read only

christian_lutter
Product and Topic Expert
Product and Topic Expert
0 Likes
3,471

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

Read only

0 Likes
3,470

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.

Read only

Former Member
0 Likes
3,470

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

Read only

0 Likes
3,470

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)

Read only

0 Likes
3,470

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.

Read only

ChrisSolomon
Active Contributor
0 Likes
3,470

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.

Read only

0 Likes
3,470

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.

Read only

former_member183045
Contributor
0 Likes
3,470

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

Read only

0 Likes
3,470

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.

Read only

0 Likes
3,470

Hi Pranay,

concatenate multiple lines to one string ...

Regards,

Klaus

Read only

matt
Active Contributor
0 Likes
3,470

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.