Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regular Expression to match exact match a URL

Posted on 2013-06-22
4
Medium Priority
?
1,530 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

876 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