Solved

Regular Expression to match exact match a URL

Posted on 2013-06-22
4
1,176 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 74

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 74

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now