case INsensitive regular expressions

Discussion in 'ASP .Net Web Controls' started by sabinosa, Oct 21, 2004.

  1. sabinosa

    sabinosa Guest

    Hi everyone,
    I am working with a RegularExpressionValidator in Visual Studio.NET.
    I would like to define a custom regular expression that ignores the
    letter case and therefore is case INsensitive. I have seen that the
    syntax might be something like "(?i)" or "/i". However, when I try to
    use that as part of my regular expression (ex. (?i)^(CSV|ZIP|TXT)$)
    the result is a javascript error. The error says: "Syntax error in
    regular expression"
    (^(CSV|ZIP|TXT)$/i does not work)

    Any idea what I am doing wrong? Thanks in advance for your responses!
     
    sabinosa, Oct 21, 2004
    #1
    1. Advertising

  2. [ Followups set ]


    sabinosa <> wrote:

    > I am working with a RegularExpressionValidator in Visual Studio.NET.


    > Any idea what I am doing wrong?



    Posting a question that is not related to Perl into the Perl newsgroup.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 21, 2004
    #2
    1. Advertising

  3. sabinosa wrote:
    > I am working with a RegularExpressionValidator in Visual Studio.NET.


    Interesting! I didn't know that Visual Studio.NET supports Perl. I guess
    there is always something new to learn.

    > I would like to define a custom regular expression that ignores the
    > letter case and therefore is case INsensitive. I have seen that the
    > syntax might be something like "(?i)" or "/i".


    Why don't you check the readily available documentation?

    From "perldoc perlre":
    Matching operations can have various modifiers. Modifiers that relate to
    the interpretation of the regular expression inside are listed below.
    Modifiers that alter the way a regular expression is used by Perl are
    detailed in the section on "Regexp Quote-Like Operators" in the perlop
    manpage and the section on "Gory details of parsing quoted constructs"
    in the perlop manpage.

    i Do case-insensitive pattern matching.

    > However, when I try to
    > use that as part of my regular expression (ex. (?i)^(CSV|ZIP|TXT)$)


    This is not a regular expression. Well, it might be, but ...

    > the result is a javascript error.


    Your system must be badly screwed up. Why would perl report a javascript
    error?

    > The error says: "Syntax error in
    > regular expression"
    > (^(CSV|ZIP|TXT)$/i does not work)


    At least the trailing /i is the correct syntax.
    Please post a short, but selfcontained program that exposes the problem,
    together with a description of what you expect the program to do versus what
    behaviour you are observing. Then we may be able to determine if the problem
    is with your code or your expectation.

    > Any idea what I am doing wrong?


    For once: not posting any actual code. How are we supposed to reproduce and
    analyse your problem if you don't tell us how.

    jue
     
    Jürgen Exner, Oct 22, 2004
    #3
  4. sabinosa

    Vijai Kalyan Guest

    (sabinosa) wrote in message news:<>...
    > Hi everyone,
    > I am working with a RegularExpressionValidator in Visual Studio.NET.
    > I would like to define a custom regular expression that ignores the
    > letter case and therefore is case INsensitive. I have seen that the
    > syntax might be something like "(?i)" or "/i". However, when I try to
    > use that as part of my regular expression (ex. (?i)^(CSV|ZIP|TXT)$)
    > the result is a javascript error. The error says: "Syntax error in
    > regular expression"
    > (^(CSV|ZIP|TXT)$/i does not work)
    >
    > Any idea what I am doing wrong? Thanks in advance for your responses!


    (Javascript question in Javascript related newsgroup might get you more help.)

    Simplest (and possibly the worst!) solution:

    i. Convert your input into UPPERCASE. In c-talk:

    int x=0;
    static char s[INPUT_BUF_SIZE];
    memset(s,'\x0',INPUT_BUF_SIZE);
    strncpy(s,input,INPUT_BUF_SIZE];
    for(; x != '\x0' && x < INPUT_BUF_SIZE ; toupper(s[x]), ++x);

    ii. Check if 's' above matches.

    iii. toupper is a macro, so this costs you time linear to size of your input.

    BTW,

    ------------------------------
    [>] RegExp Syntax

    var myRegExp = /pattern/[switch]

    In a Regular Expression /pattern/ is a Regular Expression and [switch]
    (optional) indicates the mode in which the Regular Expression is to be used:

    "i" - ignore case,
    "g" - global search,
    "gi" - global search + ignore case (case-insensitive).

    After a Regular Expression is created, it is passed to a Method of a String
    Object.
    ------------------------------

    so why not try,

    var input = /^(CSV|ZIP|TXT)$/

    ?

    The answer to your question (finally) is:

    google case insensitive pattern matching in javascript


    :)


    hth,
    ------
    vijai.
     
    Vijai Kalyan, Oct 22, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tee
    Replies:
    3
    Views:
    7,814
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Replies:
    1
    Views:
    2,482
    Mark P
    Apr 6, 2007
  3. sabinosa

    case INsensitive regular expressions

    sabinosa, Oct 21, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    130
    Matt Garrish
    Oct 22, 2004
  4. Xah Lee
    Replies:
    4
    Views:
    979
  5. Noman Shapiro
    Replies:
    0
    Views:
    234
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page