?
Solved

How to interpret:  "^\w+[\\]\w+$"

Posted on 2008-10-16
6
Medium Priority
?
381 Views
Last Modified: 2012-05-05
Greetings:

I'm trying to debug code written by another developer.  What happens is the user is prompted to enter a domain and user name in order to proceed.  The code looks like this:

s.Owner = InputBox.Show(InputBox.IOptions.O_Cancel, ..., @"^\w+[\\]\w+$", @" Enter domain\username");

I'm guessing that after the user clicks the 'OK' button, the domain and user name are processed via the regular expression.  If I were to enter the following, what should be expected?

MyDomain\JoeUser

Thanks!
0
Comment
Question by:John500
[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
  • 3
  • 3
6 Comments
 

Author Comment

by:John500
ID: 22732458
Also, if I were to test this expression using the utility seen in the picture below, can anyone tell me what the correct steps are to test the expession?  I know I have to create the object, but then what?
0
 

Author Comment

by:John500
ID: 22732466
Forgot the file:
regular-expression.JPG
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 22733116
Hi John500;

The InputBox control in your question must be a custom control, C# does not have such a form / dialog box that I can find and the version of the InputBox for Visual Basic has the syntax as followins:

Public Function InputBox( _
   ByVal Prompt As String, _
   Optional ByVal Title As String = "", _
   Optional ByVal DefaultResponse As String = "", _
   Optional ByVal XPos As Integer = -1, _
   Optional ByVal YPos As Integer = -1 _
) As String

 Which does not take strings as the last two parameters.

As far as the regex pattern, "^\w+[\\]\w+$", has the following meaning:

  1. ^ - States that the pattern will start matching from the very first character in the string
  2. \w - States to match any of the following characters a-z, A-Z, _ , 0-9
  3. + - Is a quantifier and states to match 1 or more of the previous characters
  4. [ ] - Encloses a character set and states to match any one of the character between [ and ]
  5. \\ - Because a \ is a meta-character in regex it needs to be escaped if it is one of the characters you wish to match so \\ is looking for a single \ in the input string
  6. $ - Matches the end of the string to be processed.
So the pattern, "^\w+[\\]\w+$", will match any string of character that starts with a a-z, A-Z, _ , 0-9 and 1 or more of the same characters followed by a \ followed by 1 or more of a-z, A-Z, _ , 0-9.

Will Match the following:
"MyDomain\JoeUser"
"My_Domain\JoeUser"
"MyDomain_1\JoeUser123"

Will NOT match the following:
"My-Domain\JoeUser"
"My@Domain\JoeUser"
"MyDomain_1\JoeUser#1"

Fernando
 
0
Independent Software Vendors: 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!

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 22733172
In your post using Regular Expression Demo program you do not see a result because the input string is invalid.

"\MyDomain\JoeUser"

The very first character \ causes it to fail because it is not defined by \w as being a first character. The following would be correct:


"MyDomain\JoeUser"
0
 

Author Comment

by:John500
ID: 22733985
Fernando,

Thanks much for the detailed answer.

That's what I needed .... !
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 22734201
Not a problem, always glad to help.  ;=)
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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