You want something like:
%^((https?://)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i
this is using the | to match either http://
or www
at the beginning. I changed the delimiter to %
to avoid clashing with the |
More Related Contents:
- Turn Plain Text URLs into Active Links using PHP [closed]
- PHP validation/regex for URL
- PHP regular expressions: No ending delimiter ‘^’ found in
- Replace URLs in text with HTML links
- preg_match(): Compilation failed: invalid range in character class at offset
- Remove all special characters from a string [duplicate]
- “Unknown modifier ‘g’ in…” when using preg_match in PHP?
- Optional Whitespace Regex
- How to replace text URLs and exclude URLs in HTML tags?
- Split camelCase word into words with php preg_match (Regular Expression)
- Extract URL from string
- PHP – regex to allow letters and numbers only
- Using PHP Replace SPACES in URLS with %20
- Extracting all values between curly braces regex php
- Function eregi() is deprecated [duplicate]
- Get repeated matches with preg_match_all()
- Unknown modifier ‘/’ in …? what is it? [duplicate]
- PHP – Add link to a URL in a string
- How to search in an array with preg_match?
- How to validate a domain name using Regex & PHP?
- PHP regex for validating a URL
- Regular Expressions: How to Express \w Without Underscore
- Regular expression preg_quote symbols are not detected
- Test if a string is regex
- PHP email validation [duplicate]
- How to validate that a string only contain lowercase letters?
- How to get the shortest rather than longest possible regex match with preg_match()
- Get non-numeric characters then number on each line of a block of texf
- Replace all characters that aren’t letters and numbers with a hyphen [duplicate]
- Regex to match an IP address [closed]