Solved

Regular Expression to match exact match a URL

Posted on 2013-06-22
4
1,339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 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