0

Here is the pattern:

$urlpattern = '%[^http://][^https://][\w]+(-[\w]+)*(\.[\w]+(-[\w]+)*)*\.[\w]{1,6}(\.[\w]{1,6})*[^/]%';

I have encountered a strange bug that boggles me.

When I search against a string like 'power-tool-world.com' it gimps it and returns 'ower-tool-world.com' (removes the p) but when I use any other letter(not tested on EVERY other letter) it works fine, so 'cower-tool-world.com' returns 'cower-tool-world.com' can someone please help me understand why, but more importantly give me a solution that wouldn't cause this problem?

1 Answer 1

2

The error is in the first part. When you use square brackets you match one of the characters inside them so [http://] matches h, t, p, : and /, and these characters will be excluded from the next matching group. You should use ^(http://|https://)? instead.

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

4 Comments

Not quite. [^http://] matches any character except h, t, p, : or /. And of course ^(https?://)? would be the preferable alternative.
No, although you might be on the right track, your solution returns a false, saying that power-tool-world.com does not match
Your point makes sense because both h & t return the same thing but what is the correct solution?
@Tim Pietzcker you are right but i've interpreted it as a typo because i thought that he was looking for a string that optionally starts with http:// or https://.

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.