Regular Expressions Not Matching

free web hosting
Free Web Hosting > Computers & Tech > Programming > Programming General > BASIC / Visual Basic (.NET)

Regular Expressions Not Matching

Jimmy89
Hi All,
I am using Regular Expressions in VB.NET to find illegal filename characters in a string. The user enters and name, and it then saves the file with that name. I just need to make sure that the filename doesn't contain illegal filename characters.

The characters are / \ : ? " < > | (is there any others?)

I am using the following regex at the moment, but it doesn't seem to be picking up backslashes.

CODE
Dim myRegex As New System.Text.RegularExpressions.Regex("[\/:?'=<>|]")

Every other character it picks up, why just this one? Also the " character is illegal, how can i put that into the regex (at the moment it thinks its part of the code and not the regex)

If there is another way to do the same thing, or a different regex, that would be nice! tongue.gif

Thanks,
-jimmy

 

 

 


Reply

dserban
Have you tried escaping the \ with another \ - therefore making a \\ out of it?
The same trick might work by putting a \" instead of the "
The backslash is a good guess for what the escape character is in many environments, it might be that in VB.NET it's the same as well.

Reply

faulty.lee
For " you need to escape with " itself.
CODE
""



Reply

yordan
And of course you probably need to protect \ from itself (usually \ means "ignore what follows me"). So, instead of \ you should write down \\.
I have this problem with the character $ in my script, I have to protect it, so instead of $ I write down \$.
So, amongs things not to be used in a filename, I think that you should add the following ones :
. (the dot, ".")
+ (because on Unix systems a+b will try to calculate the sum of a and b )
- (same reason, substracting)
=(a=b will be evaluated as "does the variable a be equal to the variable b" or a syntax error)
* (the star, means "everything" when interpreted by Unix or Linux)
space (the blank, " ") because "my file" will try to write down a file namde "my" and a file named "my"
$ (I guess, at least on IBM mainframe, but maybe your programs are not for mainframe ?)
And I'm sure that other forumers here will tell you a lot of other forbidden characters.
By the way, may I suggest you, if a blank or a minus is in the filename, replace it by _ (underscore) ? I see that other progs like 4image do it that way.

 

 

 


Reply

Jimmy89
Thanks guys, those changes worked a treat! (I've never liked Regular Expressions, or maybe they haven't liked me) Yordan, thanks for the little extras - I've added them in also, you can never to too safe when it comes to end users and their inputs tongue.gif!

Cheers,
-jimmy

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : regular, expressions, matching

  1. Regular Expressions
    (6)
  2. Using Regular Expressions To Parse Functions
    (5)
    I have a hierarchy of functions represented as something like:-
    @BeforeText(@AfterText(@ReadURL('http://www.quotationspage.com/quote/1.html')@,'
    ',True)@,' ',True)@ Each of the functions follow the format @FunctionName( )@. The
    ParamString itself can be composed of a string, a number or a boolean value. For example:-
    @AfterText('String', "st", True)@ - This function returns the portion of text following the
    specified substring. It is composed of three parameters. First one is the string being worked on,
    second is the substring being sou....
  3. Filtering Out Unwanted Junk Mail Using Regular Expression.
    Use this Regular Expression with the cPanel email filter to limit your (0)
    I'm so irritated with the amount of spam I get on the email accounts I have hosted at AstaHost.
    It isn't the servers fault that I get so much junk mail! It wouldn't be so bad but my
    junk mail filter on my home system doesn't scan IMAP accounts which I use since my email client
    won't separate POP3 accounts properly. So I finally got to the point I had to do
    something! I'm getting about 25 junk mail messages a day spread over 5 different email
    accounts. If I go a few days without checking my email, I have a lot of work to do to clean ....
  4. Automated Product Suggestion Script
    Compare user lists and suggest related items based on pattern matching (2)
    I recently got an idea for a project and one of the features I wanted the project to have was an
    automated suggestion service. If anyone has been to Amazon, it would work much like their
    recommended product feature. What I want to do is take several users lists of whatever but for this
    example, I'll use web links like from the browser history. I would want to suggest links to a
    user based on common links in many other users lists. User A: Amazon, Ebay, Excite, Google, Yahoo,
    MySpace, Walmart User B: Amazon, Ebay, Google, Yahoo, You Tube, MySpace, CVS User C: Amazo....
  5. The Absolute Bare Minimum Every Programmer Should Know About Regular Expressions
    (1)
    Well, the title says it all and I really don't have anything to add to that, except to say that
    this is a really, really powerful technology that is very pervasive in many programming as well as
    scripting languages and as well in mainstream database products. I really recommend you put in the
    time and effort to learn regular expressions, they are power tools that are going to open for you a
    whole new world of text processing possibilities. Link:
    http://immike.net/blog/2007/04/06/the-abso...ar-expressions/ ....
  6. How To Remove Query String Using Regular Expressions
    (4)
    Hi, I'm a complete newbie using regular expressions and what i want to do is to remove all the
    parameters of the query string of any url using regular expressions, how can i do this? For example
    if i have some urls like these: http://www.domain.com/file1.php?var1=value1&var2=value2
    http://www.domain.com/file2.php?var1=value1&var2=value2
    http://www.domain.com/file3.php?var1=value1&var2=value2 I want to only get these ones:
    http://www.domain.com/file1.php http://www.domain.com/file2.php http://www.domain.com/file3.php
    If it is possible please post no....
  7. Announcement: Importance Of Regular Site Backups !
    (18)
    This is to inform all our members that recently we've been facing a lot of hacking attempts
    from various upcoming groups - whose sole purpose seems to be defacing our members' sites. In
    most cases it's just a minor botheration though I've no clue what they're gaining out of
    it. Pertaining to this I'd like to mention that we don't employ a server-side backup
    mechanism anymore. Long time back we used to perform weekly backup of all our members' sites -
    but this service has been discontinued for a while now owing to some conflict with t....
  8. Any Active & Regular Vietnamese Member At Astahost ?
    (3)
    Hey guys, Do we have any active and regular Vietnamese member on board ? I'm looking for
    someone who's well conversant in both Vietnamese and English. Errrr.. the things that I've
    landed up with a real cute vietnamese girlfriend while I was on my Cambodia-Vietnam trip some 2
    weeks back. Problem is that she understands english, but speaks just about 10 words of it. When I
    was present there, face-to-face, our conversations still happened mostly owing to my immense
    patience and 6 years of hardcore training in Thailand - trying to drum stuff into the heads of ....
  9. Airtel GPRS
    Information about my not so regular Internet connection. (22)
    I use a SAMSUNG SGH-C200N handset coupled with Airtel (a GSM Service Provider in Asia) GPRS to
    connect to the internet. Here is a review about my Internet Connection - Points > By default
    Windows always shows the connection speed to an outstanding 115.6 KBps. Although, from what I have
    seen via the connection status, when downloading files from a good server, the maximum speed that I
    get is around 5 Kbps. During the peak hours, the connection's speed deteriorates and the data
    transmission becomes intermittent. Every Page (except for good ol' Google)....
  10. Difference Between Starter And Regular
    Do u have to manage credits differently? (3)
    If you have the default account (30 credits) do you have to post more to keep your hosting up
    compared to the starter (10 credits)? And are credit records kept before you get hosting? Because I
    didn't know that credits were reset after you get hosting. I had 30, but was planning to
    conserve credits and went for the starter. XP Thanks.....
  11. Megatsunamis
    Even more spectacular than regular ones (9)
    Megatsunamis Megatsunami. The word accurately describes what it means. Where tsunamis are big,
    megatsunamis break all limits. Tsunamis are regular surfing waves compared to these guys. They can
    rise up to be 200 meter high wall of water, destroying everything on its path. Time to take a closer
    look. On the subject tsunamis, Nathan posted this explanation: QUOTE In tribute to
    have died, I thought I'd post this! A tsunami is a series of huge waves that happen after an
    undersea disturbance, such as an earthquake or volcano eruption. (Tsunami is f....
  12. Matching Text In A MySQL Database
    (3)
    I have a database that I am using to keep track of the members to my website. THe statements I used
    to create the database are as follows: CODE create database mousling_users create table
    members(memberID int default \'0\' not null auto_increment, username
    char(20), password char(20), firstname char(20), lastname char(30),
    email char(50), privelege char(30), banned bool, primary key (memberID),
    unique id (memberID)) alter table members add fulltext (username) The re....
  13. Php Regular Expressions
    Request For Help. (11)
    So I'm trying to learn how to pull useful content from a web page. Here's what I got so
    far: CODE <?php $filename = "http://www.forum500.com"; $html =
    file_get_contents($filename); /*
    **************************************************************** */ /*                              
                                       */ /*             Got this code @ http://www.php.net/        
             */ /*                                                                  */ /*
    ***************************************************....
  14. Regular Used Terms In The Webhosting World
    (4)
    Lets begin with some regular used terms in the webhosting world: FTP - File Transfer Protocol.
    This is the service for transferring files (also the files for your website (the .html or .htm) to
    your webhost. Some webhosts offer FTP, others don't. PHP - A server-side scripting language,
    used to generate dynamic HTML on your websites. MySQL - Open Source software for a database
    management system. This can be used for forums, and other databases on the net. Also PHP can use
    this software to make a dynamic website. Domain name - This is a text name card for a comput....
  15. Matching Sound To Animations In Flash
    (2)
    This is something I worked at for a while. I used to play sounds by selecting start on the
    properties tab, and the animation never lined up with the sound waves on timeline. If you switch it
    to stream, it changes the wave and allows animation to be aligned to the sound. Also, a sound can be
    cut short by not extending the frames enough, so beware. Hope I helped again Peace Aaron....
  16. Request To Upgrade
    stater to regular (1)
    hey i have posted 70 post so i am going to ask again if i can get my upgrade
    username:wannabeeaweak Cpanel username:wannabee password:****** Cpanel password:******
    email:clovis818@aol.com website being built :www.mysitesucks.tk....
  17. Need Hosting!
    upgrade to regular hosting (1)
    ok well i know that i do not have tons of good posts ok but i do have some and i need more space
    badly because i have a web site being made on this hosting and i need more space to came my web
    site. so please upgrade my hosting username:wannabeeaweak username for Cpanel:wannabee
    password:***** password for Cpanel:***** email:clovis818@aol.com please upgrade my
    hosting!!!! I NEED IT BADLY !!!!!!!!....
  18. Upgrade from starter to regular
    (1)
    i would like a Upgrade from my starter to a regular username:wannabeeaweak login:wannabee
    password:do i have to tell email:wannabeeaweak@gmail.com....

    1. Looking for regular, expressions, matching

Searching Video's for regular, expressions, matching
advertisement




Regular Expressions Not Matching



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE