Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:54:06+00:00 2026-05-16T17:54:06+00:00

How do I use preg_match for partial matches? When I have the string: www.stackoverflow.com

  • 0

How do I use preg_match for partial matches?

When I have the string:

www.stackoverflow.com

and when I enter

stackoverflow.com or stackoverflow

to match the phrase it returns false. How do I make it work for partial matches?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:54:07+00:00Added an answer on May 16, 2026 at 5:54 pm

    preg_match uses regular expressions, which you can get a very good tutorial for here.

    In your specific case, you are looking for a string, followed by an optional segment (to change your search into English, you want to find "stackoverflow", optionally followed by ".com"). Sections of regular expressions can be made optional by using the ? modifier:

    preg_match('/stackoverflow(\.com)?/', $your_string)
    

    The regular expression here (/stackoverflow(\.com)?/) says the same thing as our English version above — match "stackoverflow" followed by an optional ".com".

    Here’s a quick overview of how the regex works:

    • The slash on each end of the pattern is a delimiter which PHP uses to enclose regular expressions.
    • The majority of characters in regular expressions are matched literally, so stackoverflow matches "stackoverflow"
    • The parentheses define a group, which is made optional by the ?. Without the group, only the token directly before the ? would be made optional (in this case the "m").
    • Note that there is a slash before the dot in ".com". This is because dots are special characters in regular expressions (used kind of like a wildcard), so it needs to be escaped if you want to match a literal dot.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I use preg_match to get a query string from a URL? http://www.example.com/imgres?imgurl=http://www.example.com/images/blue-diamond-rings.jpg
I'm trying use preg_match in an IF statement and return false if a string
I'm trying to use preg_match to extract info from href=domain.com/subdir/?key=value The info I want
I want to use preg_match to match numbers 1 - 21. How can I
How would I use the PHP function preg_match() to test a string to see
how can I use preg_match to extract secret_password from this string? s:6:secret_password
preg_match(/[\]/,'',$body); I use preg_match but I have this error here Compilation failed: missing terminating
How do I use preg_match to return an array of all substrings that match
I know how to use preg_match and preg_match_all to find the actual matches of
I want to use preg_match to return an array of every match for parenthesized

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.