![]() |
case INsensitive regular expressions
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! |
Re: case INsensitive regular expressions
[ Followups set ] sabinosa <maurof78@aol.com> 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 tadmc@augustmail.com Perl programming Fort Worth, Texas |
Re: case INsensitive regular expressions
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 |
Re: case INsensitive regular expressions
maurof78@aol.com (sabinosa) wrote in message news:<e2d435fa.0410210905.14d25ea9@posting.google. com>...
> 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)$/[i] ? The answer to your question (finally) is: google case insensitive pattern matching in javascript :) hth, ------ vijai. |
| All times are GMT. The time now is 05:45 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.