0

I have some URLs like

http://wac.0E23.ed2323sdf.net/800E13/www.myexample.gr/

http://wac.0E22.ed2323sdf.net/812E13/www.my1example.gr/

http://wac.0E23.ed2323sdf.net/802E13/www.my2example.gr/

I have to write regular expression to get the site name i.e www.myexample.gr, www.my1example.gr and www.my2example.gr

I wrote an expression to find the last occurrence of / but I am not able to capture the string between second last /.

Any idea how to achieve this?.

Regards,

1
  • can you post the regex that you have so far? Commented Sep 15, 2011 at 9:30

2 Answers 2

3

It depends on what language you're using (perl? elisp?). Usually, that would be extracted by the following:

"/([^/]+)/$"

where I put the regex between ". I do that because most languages use // as a search pattern definition in itself. And, depending on the language, the result would be in the first parenthesis value (in some languages \1, in others $1, in others (match-string 1)...)

Sign up to request clarification or add additional context in comments.

4 Comments

I was trying ([^/])+/$....Can you please explain It will help me to understand what I was doing wrong.....
Well, the + has to be inside the parenthesis to match several characters inside the group.
you are matching string between / from end right?...can you please tell me [^/] is useful here..
[^/] means a character not /, so what you do is try to get all the characters that are consecutive, and not /, and that are followed by a / and and end of line (or end of string).
2

How about this expression:

~([^/]+)/$~

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.