Exclude a single character

Results 1 to 2 of 2

Thread: Exclude a single character

  1. #1
    Join Date
    Dec 1969

    Default Exclude a single character

    HELP!<BR><BR>I&#039;m writing a file upload tool in asp.net, but it is part of a larger file sharing application written in classic asp. I want to check the name of the file that the user chooses to upload and throw an error if that filename contains a "&". (I also wouldn&#039;t be averse to replacing that character, but I can&#039;t seem to get anything to work)<BR><BR>I&#039;m attempting to use a regular expression to match against:<BR><BR>&#060;code&#062;Dim testExp As Regex = New regex("![&]")&#060;/code&#062;<BR><BR>where "![&]" is my feeble attempt at a regular expression. I&#039;m not familiar with perl, but some of the people I&#039;ve talked to in my office insist that regular expressions are perl and that the "!" is equivalent to "not". Please help!<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default You really shouldn't use regexps here.

    Rather, just use VBScript&#039;s INStr function. You can do:<BR><BR>If InStr(1, stringToSearch, subStringToLookFor) &#062; 0 then<BR> &#039;The substring was found in the string to search<BR>Else<BR> &#039;It was not!<BR>End If<BR><BR><BR>Using regular expressions for this problem is harder than it may seem. The correct syntax, btw, would be:<BR><BR>[^&]<BR><BR>but that would match any character other than &. Meaning if you used it on the string "hello&goodnight" it would have a match on every character other than the &.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts