-3

I have a regular expression of JavaScript, which is given below

/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g

and I need to use it in PHP, so I need PHP version of this regular expression, any idea please?

5
  • 2
    This previous SO question should help you find the way: [stackoverflow.com/questions/2621583/… [1]: stackoverflow.com/questions/2621583/… Commented Dec 27, 2013 at 22:15
  • 1
    I think it will be the same in PHP, nothing different. Commented Dec 27, 2013 at 22:16
  • It is not a valid PHP regex. Commented Dec 27, 2013 at 22:28
  • 2
    It's mostly valid in PHP, apart from the unnecessary flag. Google the error message you're getting but forgot to include in your question. Commented Dec 27, 2013 at 22:30
  • It filters URLs in given text, not validate email. Commented Dec 27, 2013 at 22:34

1 Answer 1

0

Cleaned up, it would probably look like this (without the //g modifier)

 # '~((([A-Za-z]{3,9}:(?://)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,w]+@)[A-Za-z0-9.-]+)((?:/[+\~%/.\w-]*)?\??(?:[-+=&;%@.\w]*)\#?(?:[.!/\\\\\w]*))?)~'

 (                                          # (1 start)
      (                                          # (2 start)
           (                                          # (3 start)
                [A-Za-z]{3,9} :
                (?: // )?
           )                                          # (3 end)
           (?: [-;:&=+$,\w]+ @ )?
           [A-Za-z0-9.-]+ 
        |  (?: www\. | [-;:&=+$,w]+ @ )
           [A-Za-z0-9.-]+ 
      )                                          # (2 end)
      (                                          # (4 start)
           (?: / [+\~%/.\w-]* )?
           \??
           (?: [-+=&;%@.\w]* )
           \#?
           (?: [.!/\\\w]* )
      )?                                         # (4 end)
 )                                          # (1 end)
Sign up to request clarification or add additional context in comments.

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.