0

Admit that I suck in writing regular expression. Please help me to solve how to write regular expression for success-apply founded in URL just like http://www.example.com/success-apply/

5
  • Why would you need a regex for that? Commented Dec 15, 2015 at 10:13
  • @DavidBrabant need to set a goal in google analystics. Commented Dec 15, 2015 at 10:15
  • I mean, why can't you use a string replace instead? Commented Dec 15, 2015 at 10:15
  • @DavidBrabant just find whether success-apply is included in URL string or not. Commented Dec 15, 2015 at 10:17
  • url.Contains("success-apply") ? Commented Dec 15, 2015 at 10:19

2 Answers 2

1

Assuming that the pattern success-apply changes:

example\.com\/([^\/]+)
# capture everything that is not a forward slash one or unlimited times

Here is this regex example with PCRE (PHP).

If you however only want to know if the string is there at all, regular expressions seem a bit of an overkill. Consider the following PHP code:

if (strpos($url, 'success-apply') !== FALSE) {
   // do sth useful
}
Sign up to request clarification or add additional context in comments.

Comments

0

Is this what you are looking for?

(success-apply)

2 Comments

I think this answer is incorrect... because you are not finding the match sucess-apply in an url... you re finding in the entire text, whatever it is
You mean I'm not checking if it's a valid url before I'm searching for the keyword? I don't think this is what the OP is asking for. He has a list of urls (I assume), wether they are valid or not is in this case not the question, but if these strings contain the keywords or not.

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.