Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to exclude a character in a regex pattern character class if last character?
    primarykey
    data
    text
    <p>Sorry if the question is phrased poorly (or if already asked. I really tried to find it).</p> <p>Is it possible, if one specific character in a character class happens to be the last character (though it can still remain elsewhere) to exclude it from the match? What I am working with is similar to finding urls in larger strings, and need to include periods in the pattern but IF the last character is a period, exclude it as the end of a sentence.</p> <p>So in a pattern (other url stuff) "(/[a-zA-Z0-9._-]*)?" is there a way to exclude ONLY the last period, if present? Note that the above would specifically be the uri segments after the domain, but I want to match only </p> <pre><code>"/some_uri/segments.php" </code></pre> <p>in both </p> <pre><code>"www.domain.com/some_uri/segments.php" </code></pre> <p>AND </p> <pre><code>"www.domain.com/some_uri/segments.php." </code></pre> <p>while allowing for more than one period to exist in the uri.</p> <p>If the above isn't clear, imagine I am asking for a way to exclude the final letter in a word, if and only if it is a 'z'. So 'dozzer' and 'dozzerz' both match as 'dozzer' inside a sentence structure (so... no matching to the position at the END of a string). I've played around with lookaheads and the like, but haven't found a way yet. I'm wondering if it's not possible (in just a single regex).</p> <p>Thanks for your time!</p> <p><em>EDIT</em></p> <p>I apologize for not making it clearer, but I need to perform the match inside of a BLOCK of text. What I'm doing is going through text and finding all the web addresses and applying markup to them. Thus I CAN'T utilize positional operators, such as $ to match the end of the string. Which has been the biggest problem. </p> <p>Unless someone else posts an answer that works after this, I think I'm going to have to agree with M477h3w1012 and conclude that it can't be accomplished inside the regex alone. I'm going to need to perform a conditional check after finding matches to determine if they have a trailing period. But thank you all, again, very much for your time and help. :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload