SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Almasty's Avatar
    Join Date
    Mar 2009
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question RegEx: Just the lowercase, just the lowercase

    Hi

    This is a regex question.

    I am trying to match a set of URLs. Some of the URLs contain a GUID, something like this:

    Code:
    http://www.example.com/newsroom/press/release/?id=8a0223ba-af12-4406-a4a5-af603c0a1364
    However, there are also URLs in the list I am searching that contain uppercase versions of this URL:

    Code:
    http://www.example.com/newsroom/press/release/?id=8A0223BA-AF12-4406-A4A5-AF603C0A1364
    or structures like:

    Code:
    http://www.example.com/issues/polls/
    http://www.example.com/mystory/?rid=1234&quote=Here I am
    I am trying (but not very well) to construct a Regular Expression that will match any URL in my list, but if it contains a GUID only match GUIDs that are comprised of lower case characters.

    So, using the examples above these URLs would be OK

    Code:
    http://www.example.com/newsroom/press/release/?id=8a0223ba-af12-4406-a4a5-af603c0a1364
    http://www.example.com/issues/polls/
    http://www.example.com/mystory/?rid=1234&quote=Here I am
    But this one would not match

    Code:
    http://www.example.com/newsroom/press/release/?id=8A0223BA-AF12-4406-A4A5-AF603C0A1364
    n.b that the upper case GUID is not always at the end of the string (which is something I made a mistake by placing a $ in at the end).

    Does anyone have an idea of how to achieve this `if specific string pattern exist, only match if it is lowercase. If it does not exist, then accept string.`

    Al

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,032
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Almasty View Post
    Does anyone have an idea of how to achieve this `if specific string pattern exist, only match if it is lowercase. If it does not exist, then accept string.`
    Isn't this the same as "if the string contains an uppercase GUID reject it, otherwise accept it"?
    If it is, I think you'll know what to do
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code Perl:
    $url='http://www.example.com/mystory/?rid=1234&quote=Here I am';
    my ($guid) = ($url =~ m/.[^\?]*r?id=[a-z\-\d]*/)


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •