Jump to content

Recommended Posts

Hello,

 

I got a JavaScript URL Validation Regex, since I'm not used-to with Regex I need help converting it  into PHP regex.

 

Here is a JavaScript Regex

/^https?\:\/\/(www\d?\d?\d?\d?\.)?([A-Za-z0-9-_]+\.)?[A-Za-z0-9-_]+((\.[A-Za-z]{2,6})(\.[A-Za-z]{2})?([0-9-_%&\?\/\.=]*))$/

 

I need this particular regex in PHP

 

 

Thanks in advance

the regex is the same (the syntax is the same, though I can't vouch for the soundness of your pattern without knowing details...but if you know your current pattern works for you, then okay), but you would use the pattern in something like preg_match

 

example:

 

preg_match("/.../",$contentToMatch,$matches);
echo "<pre>";
print_r($matches);

 

first argument is the pattern, 2nd is the subject, 3rd are results of captured matches.  Or if you are not caring about the captured groups and just wanting to know if the pattern matched overall:

 

if (preg_match("/.../",$contentToMatch)) {
  // matched
} else {
  // did not match
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.