This is not working as I intended it to, regardless it's running my if clause even if my email format is: something like hello@gmail.com not sure what is wrong here.          Regex RX = new Regex("^[a-zA-Z0-9]{1,20}@[a-zA-Z0-9]{1-20}.[a-zA-Z]{2,3}$");         if (!RX.IsMatch(textEmail.Text))         {             MessageBox.Show("Email format is not correct");         }          else         {             MessageBox.Show("Email format is CORRECT");         }   it should really run the else clause
835
Over the years I have slowly developed a  that validates MOST email addresses correctly, assuming they don't use an IP address as the server part.  I use it in several PHP programs, and it works most of the time.  However, from time to time I get contacted by someone that is having trouble with a site that uses it, and I end up having to make some adjustment (most recently I realized that I wasn't allowing 4-character TLDs).  What is the best regular expression you have or have seen for validating emails?  I've seen several solutions that use functions that use several shorter expressions, but I'd rather have one long complex expression in a simple function instead of several short expression in a more complex function.
113519
I'm having a save method with several Conditions in it.Here is my apex class  invoiceset = [select SiteUrl__c, Prefix__c,Seperator__c,Seperator1__c,DateValue__c,DateValue1__c,Date_Format__c,Incrementer__c,Counter_Val1__c,counter__c from Invoice_setting__c limit 1];        if(invoiceSet[0].DateValue__c == 'Date' &amp;&amp; invoiceSet[0].DateValue1__c == 'Date'){         if(invoiceSet[0].Date_Format__c == 'dd-mm-yyyy'){              datenow = DateTime.now().format('dd-MM-yyyy');                   }else if(invoiceSet[0].Date_Format__c == 'MM-dd-yyyy'){              datenow = DateTime.now().format('MM-dd-yyyy');                     }else if(invoiceSet[0].Date_Format__c == 'dd/MM/yyyy'){              datenow = DateTime.now().format('dd/MM/yyyy');          }else if(invoiceSet[0].Date_Format__c == 'mm/dd/yyyy'){              datenow = DateTime.now().format('mm/dd/yyyy');          }else if(invoiceSet[0].Date_Format__c == 'yy'){              datenow = DateTime.now().format('yy');          }else if(invoiceSet[0].Date_Format__c == 'yyyy'){              datenow = DateTime.now().format('yyyy');          }           prefixName = invoiceset[0].prefix__c + invoiceSet[0].seperator__c + datenow + invoiceset[0].Seperator1__c + datenow;       }      else if(invoiceSet[0].DateValue__c == 'Counter' &amp;&amp; invoiceSet[0].DateValue1__c == 'Counter'){       if(invoiceSet[0].counter_val1__c == null){          invoiceSet[0].Counter_Val1__c = invoiceset[0].Counter__c;        }else if(invoiceSet[0].Counter_Val1__c == invoiceset[0].Counter__c){            intt = integer.valueof(invoiceSet[0].Counter__c) + integer.valueOf(invoiceSet[0].Incrementer__c) ;            invoiceSet[0].Counter_Val1__c = string.valueOf(intt) ;        }else {             intt = integer.valueof(invoiceSet[0].Counter_Val1__c) + integer.valueOf(invoiceSet[0].Incrementer__c) ;            invoiceSet[0].Counter_Val1__c = string.valueOf(intt) ;        }        update invoiceset;         prefixName = invoiceset[0].prefix__c + invoiceSet[0].seperator__c + invoiceSet[0].Counter_Val1__c + invoiceset[0].Seperator1__c +invoiceset[0].Counter_Val1__c;       } &amp;&amp; so on........   Inorder to cover all this conditions should I write those many methods or any other easy way?  Here is my Test Code  public static testmethod void test(){    invoice_setting__c setng = new invoice_setting__c(Name='Invoice Settings',SiteUrl__c='www.google.com',Prefix__c='Test',Seperator__c = '-',dateValue__c = 'Date',Seperator1__c = '/',dateValue1__c = 'Date',date_format__c='dd-mm-yyyy');     insert setng; } public static testmethod void test1(){     invoice_setting__c setng1 = new invoice_setting__c(Name='Invoice Settings',Prefix__c='Test',Seperator__c = '-',dateValue__c = 'Counter',Seperator1__c = '/',Counter_Val1__c=null,dateValue1__c = 'Counter',date_format__c='dd-mm-yyyy',Incrementer__c='10');     insert setng1; } &amp; so on......   Any Suggestions for this please
10465
Please support the use of nested expressions like  and (or ) when searching.  Looking here, on meta, at questions tagged   and at questions found with +search +tag +boolean I didn't see any information on this topic.
80203
This error should be a simple one but I cant seem to make it work. The problem lies in the fact that this very same code works earlier in the program. I don's see any reason for it to be sending an error on this instance and not the four previous ones. Reference the code below, and feel free to provide any criticism you may have as it should make me better. If it matters, I am using Sharp Develop 2.2.  Here is an example of the code that works:  void calc2Click(object sender, EventArgs e) {     if (!String.IsNullOrEmpty(tb2_fla.Text) &amp; String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) &amp; String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text))     {         MessageBox.Show("Enter either kVA and Voltage or FLA and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);     }                 if (!String.IsNullOrEmpty(tb2_kva.Text) &amp; !String.IsNullOrEmpty(tb2_e.Text))     {              decimal x, y, z;             x = decimal.Parse(tb2_kva.Text);                   y = decimal.Parse(tb2_e.Text);             z = (x * 1000) / (1.732050808m * y); //the m at the end of the decimal allows for the multiplication of decimals                 tb2_fla.Text = z.ToString();             tb2_fla.Text = Math.Round(z,2).ToString();     }         else     {         if (!String.IsNullOrEmpty(tb2_fla.Text) &amp; !String.IsNullOrEmpty(tb2_e.Text))     {              decimal x, y, z;             x = decimal.Parse(tb2_fla.Text);                   y = decimal.Parse(tb2_e.Text);             z = (x * y * 1.732050808m) / 1000; //the m at the end of the decimal allows for the multiplication of decimals               tb2_kva.Text = Math.Round(z,2).ToString();      }   Here is the example of the code that sends the error in the subject line of this post:  void Calc4Click(object sender, EventArgs e) {         if (!String.IsNullOrEmpty(tb4_fla.Text) &amp;&amp; String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_kw.Text) &amp; String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_e.Text))         {   //If values are entered improperly, the following message box will appear         MessageBox.Show("Enter either FLA and Voltage or kW and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);         }              if (!String.IsNullOrEmpty(tb4_fla.Text)&amp;&amp; !String.IsNullOrEmpty(tb4_e.Text)&amp;&amp; String.IsNullOrEmpty(tb4_kw.Text))         {//If the user eneters FLA and Voltage calculate for kW              decimal x, y, z;             x = decimal.Parse(tb4_fla.Text);             y = decimal.Parse(tb4_e.Text);             z = (x*y)*(.8 * 1.732050808m);             tb4_kw.Text = Math.Round(z,0).ToString();          }                         if (!String.IsNullOrEmpty(tb4_kw.Text) &amp;&amp; !String.IsNullOrEmpty(tb4_e.Text) &amp;&amp; String.IsNullOrEmpty(tb4_fla.Text))         {;//If the user enters kW and Voltage calculate for FLA             decimal x, y, z;             x = decimal.Parse(tb4_kw.Text);             y = decimal.Parse(tb4_e.Text);             z = (1000 * x)/(y * 1.732050808m)* .8;             tb4_fla.Text = Math.Round(z,0).ToString();         }      }   I appreciate any help that I can get.  Thank you.
42865
Can anyone help me with this question: I know it before, but I have tried to solve it myself and didnt succeed. what is the regular expression for this language: L=all words that have 00 or 11 but not both.  Thank you!
83296
I am using the  validation plugin. Great stuff! I want to migrate my existing ASP.NET solution to use jQuery instead of the ASP.NET validators. I am missing a replacement for the regular expression validator. I want to be able to do something like this:  $("Textbox").rules("add", { regularExpression: "^[a-zA-Z'.\s]{1,40}$" })   How do I add a custom rule to achieve this?
2156
In Java is there a way to check the condition:  "Does this single character appear at all in string x"  without using a loop?
19052
Is it possible to use a RegEx to validate, or sanitize Base64 data?  That's the simple question, but the factors that drive this question are what make it difficult.  I have a Base64 decoder that can not fully rely on the input data to follow the RFC specs.  So, the issues I face are issues like perhaps Base64 data that may not be broken up into 78 (I think it's 78, I'd have to double check the RFC, so don't ding me if the exact number is wrong) character lines, or that the lines may not end in CRLF; in that it may have only a CR, or LF, or maybe neither.  So, I've had a hell of a time parsing Base64 data formatted as such.  Due to this, examples like the following become impossible to decode reliably.  I will only display partial MIME headers for brevity.  Content-Transfer-Encoding: base64  VGhpcyBpcyBzaW1wbGUgQVNDSUkgQmFzZTY0IGZvciBTdGFja092ZXJmbG93IGV4YW1wbGUu   Ok, so parsing that is no problem, and is exactly the result we would expect.    And in 99% of the cases, using any code to at least verify that each char in the buffer is a valid base64 char, works perfectly.  But, the next example throws a wrench into the mix.  Content-Transfer-Encoding: base64  http://www.stackoverflow.com VGhpcyBpcyBzaW1wbGUgQVNDSUkgQmFzZTY0IGZvciBTdGFja092ZXJmbG93IGV4YW1wbGUu   This a version of Base64 encoding that I have seen in some viruses and other things that attempt to take advantage of some mail readers desire to parse mime at all costs, versus ones that go strictly by the book, or rather RFC; if you will.  My Base64 decoder decodes the second example to the following data stream.  And keep in mind here, the original stream is all ASCII data!  [0x]86DB69FFFC30C2CB5A724A2F7AB7E5A307289951A1A5CC81A5CC81CDA5B5C1B19481054D0D 2524810985CD94D8D08199BDC8814DD1858DAD3DD995C999B1BDDC8195E1B585C1B194B8   Anyone have a good way to solve both problems at once?  I'm not sure it's even possible, outside of doing two transforms on the data with different rules applied, and comparing the results.  However if you took that approach, which output do you trust?  It seems that ASCII heuristics is about the best solution, but how much more code, execution time, and complexity would that add to something as complicated as a virus scanner, which this code is actually involved in?  How would you train the heuristics engine to learn what is acceptable Base64, and what isn't?    UPDATE:  Do to the number of views this question continues to get, I've decided to post the simple RegEx that I've been using in a C# application for 3 years now, with hundreds of thousands of transactions.  Honestly, I like the answer given by  the best, which is why I picked it as the selected answer.  But to anyone using C#, and looking for a very quick way to at least detect whether a string, or byte[] contains valid Base64 data or not, I've found the following to work very well for me.  [^-A-Za-z0-9+/=]|=[^=]|={3,}$   And yes, this is just for a STRING of Base64 data, NOT a properly formatted  message.  So, if you are dealing with data of this type, please take that into account before attempting to use the above RegEx.  If you are dealing with Base16, Base32, Radix or even Base64 for other purposes (URLs, file names, XML Encoding, etc.), then it is highly recommend that you read  that  mentioned in his answer as you need to be well aware of the charset and terminators used by the implementation before attempting to use the suggestions in this question/answer set.
108524
I need a RegEx pattern for extracting all the properties of an image tag.  As we all know, there are lots of malformed HTML out there, so the pattern has to cover those possibilities.  I was looking at this solution  but it didn't quite get it all:  I come up something like:  (alt|title|src|height|width)\s*=\s*["'][\W\w]+?["']   Is there any possibilities I'll be missing or a more efficient simple pattern?  EDIT: Sorry, I will be more specific, I'm doing this using .NET so it's on the server side. I've already a list of img tags, now I just need to parse the properties.
10138
I received the following exception when I was using the Regex class with the regular expression: (?'named a'asdf)  System.ArgumentException: parsing \"(?'named a'asdf)\" - Invalid group name: Group names must begin with a word character.   What is the problem with my regular expression?
37488
This works just fine:      protected void txtTest_Load(object sender, EventArgs e)     {         if (sender is TextBox) {...}      }   Is there a way to check if sender is NOT a TextBox, some kind of an equivalent of != for "is"?  Please, don't suggest moving the logic to ELSE{} :)
100322
I have the following validation rule ;  OR(      AND(         Upper(MailingCountry) &lt;&gt; 'UK',             NOT(ISBLANK(TEXT(UK_Email_Consent__c)))     ),      AND(        Upper(MailingCountry) = 'UK',          ISBLANK(TEXT(UK_Email_Consent__c))     ) )   I know to exclude system admins I need to include the following line   $Profile.Name &lt;&gt; "System Administrator"   In the validation rule above where do I add profile &lt;> system admin   Looking forward to your help   many thanks
123924
I'm trying to match a string pattern to any string in an array:  SELECT 'abc' LIKE ANY('{"abc","def"}') -- TRUE  -- BUT  SELECT 'ab%' LIKE ANY('{"abc","def"}') -- FALSE, I expect TRUE   What is wrong with the second query?
52191
If there's a "First World Problems" for scripting, this would be it.   I have the following code in a script I'm updating:  if [ $diffLines -eq 1 ]; then         dateLastChanged=$(stat --format '%y' /.bbdata | awk '{print $1" "$2}' | sed 's/\.[0-9]*//g')          mailx -r "Systems and Operations &lt;sysadmin@[redacted].edu&gt;" -s "Warning Stale BB Data" jadavis6@[redacted].edu &lt;&lt;EOI         Last Change: $dateLastChanged          This is an automated warning of stale data for the UNC-G Blackboard Snapshot process. EOI  else         echo "$diffLines have changed" fi   The script sends email without issues, but the mailx command is nested within an if statement so I appear to be left with two choices:    Put EOI on a new line and break indentation patterns or Keep with indentation but use something like an echo statement to get mailx to suck up my email.   I'm open to alternatives to heredoc, but if there's a way to get around this it's my preferred syntax.
35188
I didn't get the answer to this anywhere. What is the runtime complexity of a Regex match and substitution?  Edit: I work in python. But would like to know in general about most popular languages/tools (java, perl, sed).
116653
I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?
58651
Does anybody know if there is a way to evaluate a string containing boolean-logic at runtime? My logic, can only contain three operators and parenthesis (AND, OR, NOT). I can even make the string look like this: true &amp;&amp; false &amp;&amp; (true || !true)  I don't have the bandwidth to build a full-on parser... Any ideas?  PS: I saw some answers that pointed to the use of an API but I don't have access to use the Toolkit API in the environment this will get deployed.