Solved

Regular Expression to match exact match a URL

Posted on 2013-06-22
4
1,284 Views
Last Modified: 2013-06-22
Hi,
I am trying to write a regular expression that will exact match against URL:
http://student-intranet.registration:2013/RegNow/complete/confirmation.html 

I put together this [^]/RegNow/complete/confirmation.html[^]

But when running the regular expression it matches against other URLS:
http://student-intranet.registration:2013/RegNow/regformreview.html
http://student-intranet.registration:2013/RegNow/complte/processing
http://student-intranet.registration:2013/RegNow/regform.html
http://student-intranet.registration:2013/RegNow/complete/confirmation.html 

What should I change in the syntax for an exact match?
[^]/RegNow/complete/confirmation.html[^]
0
Comment
Question by:jay_eire
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39268378
I don't have any reason to suspect that the following would not work.

/RegNow/complete/confirmation\.html$

Open in new window

0
 
LVL 7

Author Comment

by:jay_eire
ID: 39268382
Thanks Kaufmed, can I ask what \ and $ do exactly?

Also was I wrong in using [^]
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39268426
The \ escapes the dot. Dot (unescaped) in regex means "any character". While dot would still match the dot within the filename, it's more correct to explicitly escape the dot when you actually mean to locate a dot.

The $ means "end of string." It's not an actual character, but rather a place within the string. Similarly ^ means "start of string."

Your use of [^], in contradiction to what I just described with respect to ^ is actually something different. Square brackets ( [] ) within regex denote a "character class," which is a listing of characters that you would like any of to match. If I gave you "[abc]", for example, then I would be saying that I want to match either an "a", "b", or "c" character. But not all. Only one of the characters listed, in this example, should match within the target string. This is due to how I wrote the character class. There are ways to make it match more than one.

I am not certain that [^] will compile as a valid expression, however. There is one more peculiarity with ^ and square brackets. Above I mentioned that [abc] would match any single instance of either of those characters. If I include a ^ in this manner:

    [^abc]

...then I am saying that I want to match any character that is not ( ^ ) an "a", "b", or "c". ^ as the first character of a character class negates the character class, and causes the character class to mean "any character not one of the ones listed." I cannot immediately recall if [^] is a valid expression or not. Nevertheless, I do not thing that [^] was necessary for your pattern.

P.S.

In order to say "any character not a ^," you would actually do:

    [^^]
0
 
LVL 7

Author Closing Comment

by:jay_eire
ID: 39268442
Thank you for the solution and explanation.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question