Skip to content
Fix Code Error

Match the path of a URL, minus the filename extension

March 13, 2021 by Code Error
Posted By: Anonymous

What would be the best regular expression for this scenario?

Given this URL:

http://php.net/manual/en/function.preg-match.php

How should I go about selecting everything between (but not including) http://php.net and .php:

/manual/en/function.preg-match

This is for an Nginx configuration file.

Solution

Like this:

if (preg_match('/(?<=net).*(?=.php)/', $subject, $regs)) {
    $result = $regs[0];
}

Explanation:

"
(?<=      # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
   net       # Match the characters “net” literally
)
.         # Match any single character that is not a line break character
   *         # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
(?=       # Assert that the regex below can be matched, starting at this position (positive lookahead)
   .        # Match the character “.” literally
   php       # Match the characters “php” literally
)
"
Answered By: Anonymous

Related Articles

  • Reference - What does this regex mean?
  • What are the undocumented features and limitations…
  • Nginx refuses to read custom nginx.config when dockerized
  • Dockerize next.js and nginx at one Dockerfile
  • How to use Regular Expressions (Regex) in Microsoft…
  • nginx docker alpine envsubst doesn't work when…
  • Using variables in Nginx location rules
  • C# parse FHIR bundle - read resources
  • How can I resolve Web Component Testing error?
  • Show scroll update when scrolling down page
  • Reference — What does this symbol mean in PHP?
  • Nginx fails to load css files
  • PHP-FPM and Nginx: 502 Bad Gateway
  • Nginx try_files not working for my Vue app
  • nginx - nginx: [emerg] bind() to [::]:80 failed (98:…
  • AppCompat v7 r21 returning error in values.xml?
  • How to search in an array with preg_match?
  • Is there a way to use nextjs with docker and nginx
  • How do I install soap extension?
  • nginx / docker / ssl for localhost
  • NextJS deploy to a specific URL path
  • Dafny prove lemmas in a high-order polymorphic function
  • How to create websockets server in PHP
  • Ukkonen's suffix tree algorithm in plain English
  • shell script. how to extract string using regular…
  • Is it possible to apply CSS to half of a character?
  • Is there a regular expression to detect a valid…
  • using d3.js with aurelia framework
  • Jenkins with nginx using docker Port 50000 config
  • Docker Networking - nginx: [emerg] host not found in…
  • Nginx configuration setup for windows
  • Regex to match only uppercase "words" with some exceptions
  • What's the difference between eval, exec, and compile?
  • Re-arrange position in a table maitaining order
  • Upload video files via PHP and save them in…
  • Footer not staying at the bottom when scrolling
  • nginx: [emerg] "server" directive is not allowed here
  • getting error while updating Composer
  • Octave using 'for' statement to show two animations…
  • Undefined reference to 'vtable for ✘✘✘'
  • regex match any single character (one character only)
  • What is your most productive shortcut with Vim?
  • How to check if a string contains only digits in Java
  • Error: getaddrinfo ENOTFOUND…
  • How to negate the whole regex?
  • Regex lookahead, lookbehind and atomic groups
  • How do you parse and process HTML/XML in PHP?
  • Regular expression to check if password is "8…
  • Node.js + Nginx - What now?
  • How many times the loss function is triggered from…
  • Need to extract text in a C# Regex
  • Swift extract regex matches
  • PHP recursive function not allowing page to load
  • Adding Regex to a Vue.js Data Object
  • "configuration file /etc/nginx/nginx.conf test…
  • How to use html template with vue.js
  • Regular expression to match numbers with or without…
  • NGINX reverse proxy to .netcore app gives bad gateway 502
  • How can I parse a CSV string with JavaScript, which…
  • How to calculate the angle between a line and the…
  • Is there some way to test my grammar which refer to…
  • RegEx match open tags except XHTML self-contained tags
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • How do I use Assert.Throws to assert the type of the…
  • Regular expression for letters, numbers and - _
  • How to validate an email address using a regular expression?
  • Nextjs getInitialProps not working with NGINX
  • Ember JS tutorial: TypeError: Cannot read property…
  • Formatting pricing cards in Bootstrap
  • BehaviorSubject vs Observable?
  • How to show title in hover - css / jquery
  • How to split a string in Java
  • How do you sign a Certificate Signing Request with…
  • Combining only single characters in starting of…
  • How to define startup file in…
  • Regex matching in a Bash if statement
  • Set a 10-second timer for each subject input
  • Trying to match today's date with list of custom…
  • Why does C++ code for testing the Collatz conjecture…
  • PHP - Failed to open stream : No such file or directory
  • Tokenize mathematic string expression
  • How to correctly link php-fpm and Nginx Docker containers?
  • Does C# have extension properties?
  • 'equal' is not defined : Ember-qunit does not seem…
  • Start redis-server with config file
  • AWS Beanstalk couldn't create nginx config file at…
  • How to print a number with commas as thousands…
  • What is a non-capturing group in regular expressions?
  • Nginx redirection different with IP behavior on 2…
  • why nginx ingress controller is deployed as a…
  • How to unescape a Java string literal in Java?
  • Validate that a string is a positive integer
  • create pascol voc xml from csv
  • C threads corrupting each other
  • How do I restart nginx only after the configuration…
  • Replacement for lookbehind in std::regex
  • filter and sort an array of objects in Vue
  • List tables in a PostgreSQL schema
  • NGinx Default public www location?
  • Elegant ways to support equivalence ("equality") in…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to get current time and date in C++?

Next Post:

Extracting specific columns from a data frame

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error