Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Request for a new complex regex

Last post 09-11-2008, 5:14 PM by arunkaggarwal. 12 replies.
Sort Posts: Previous Next
  •  09-04-2008, 1:39 PM 45967

    Request for a new complex regex

    Hi RegEx experts

     I have the requirements as below to create a regex for my application.

    The string should not have the following

    1) Space should not be allowed

    2) <any text> should not be allowed

    3) <! should not be allowed

    4) &# should not be allowed

    5) script: should not be allowed

    6) expression( should not be allowed

    7) " on... =" should not be allowed (on preceded by a space, followed by alpha characters and spaces and followed by =)

    I will appreciate your help deeply from the bottm of my heart. My head is spinning trying to figure out all the commands and fitting all the above requirements above together. I know someone is out there for which it is a piece of cake.

    Sincerely

    -Arun

    Filed under:
  •  09-04-2008, 2:20 PM 45976 in reply to 45967

    Re: Request for a new complex regex

    What regex engine are you using?  By space do you mean just the " " space character or do you mean any whitespace character?  You want to allow !> but not <! ?  It might also be best if you provide a real text example of what might be submitted and what you don't want.
  •  09-04-2008, 2:58 PM 45981 in reply to 45976

    Re: Request for a new complex regex

    Hi ddrudik

    Thanks for your reply. All your questions are valid. Below is the answers as I know it.

    1) Space is a white space only " "

    2) Yes, allow !> but do not allow <!

    3) It should not allow "" (quotes) also

    4) It should not allow | (pipe) also

    Example.

    The string xxx<xxx>xx not allowed

    The string xxxscript:xx not allowed

    the string xxx xxx not allowed

    the string xxx<xxx xxx>xxx not allowed

    the string xxx|xxx not allowed

    the string xxx<!xxx not allowed

    the string xxxexpression(xxx not allowed

    the string xxx onxxx= xxx not allowed

    Hope it helps

    Thanks for your help again

    Regards

    -Arun

     

  •  09-04-2008, 3:15 PM 45982 in reply to 45981

    Re: Request for a new complex regex

    You should be able to regex test operation with (note any match is to be considered a string that is not allowed):

    (?=.*["| ]|(?:<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=))


  •  09-04-2008, 3:36 PM 45984 in reply to 45982

    Re: Request for a new complex regex

    Hi

    I know you asked me the question what engine? I am using .NET engine.

    When I try your regex below, I get the following error.Is it because of .NET engine?

    ------------------------------------------------------------------ 

    There was an error in the regular expression!

    parsing "(?=.*["| ]|(?:<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=))" - Not enough )'s.

    Parameter name: (?=.*["| ]|(?:<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=))

    ------------------------------------------------------------------ 

    What am I missing?

    Thanks

    -Arun

     

  •  09-04-2008, 3:40 PM 45985 in reply to 45984

    Re: Request for a new complex regex

    VB or C#?
  •  09-04-2008, 3:47 PM 45987 in reply to 45985

    Re: Request for a new complex regex

    C#
  •  09-04-2008, 3:56 PM 45989 in reply to 45987

    Re: Request for a new complex regex

  •  09-04-2008, 8:47 PM 45996 in reply to 45989

    Re: Request for a new complex regex

    hi ddrudik

    Thankyou so much. It works!!!!

    Please send me your address. I would like to send you a small token of appreciation. I needed help and you have been my saviour.

    Best Regards

    -Arun

  •  09-05-2008, 6:30 AM 46018 in reply to 45996

    Re: Request for a new complex regex

    Your words of appreciation are enough payment for me, thanks though.  If you need another regex solution in the future feel free to stop back to this forum anytime.


  •  09-10-2008, 2:41 PM 46215 in reply to 46018

    Re: Request for a new complex regex

    Hi Doug

    I do not have to refer you as ddrudik since I looked at your profile and found your real name. Sorry for refering to you as ddrudik earlier!!!

    I have few related questions to this regex. I am trying to understand the basics of this regex string so that I can create some variations myself without bugging you all the time. The string you gave is as follows.

    (?=.*["| ]|(?:<!|expression\(|<[^>]*>|&#|script:| on[a-z]+=))

    Can you please explain me the basics of the string above? Specifically my questions are as below

    Q1) (?=.*["| ]|(?:<!|expression\(|<[^>]*>|&#|script:| on[a-z]+=)) - The bolded sequence ["| ] restricts the character " (quote) or | (pipe) or space from the string right? That means if I have to create a regex which needs to restrict only " (quote) and | (pipe) then I can change the regex to (?=.*["|]|(?:<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=)) and it will work right?

    Q2) If I do not need to restrict any of these characters (" (quote) or | (pipe) or space) , can I change the regex to (?=.*[]|(?:<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=)) or there is a better way?

    Q3) (?=.*["| ]|(?:<!|expression\(|<[^>]*>|&#|script:| on[a-z]+=)) - The bolded sequence is restricting the special sequences like <> etc right. Looking at the .net help, (?: matches pattern without capturing it. Just for my understanding, can we include the restrictions mentioned in Q1 as part of this sequence (?: and make it simple. Why we have 2 separate sections in the regex to restrict the characters in Q1 and character sequences like <> etc.

    Q4) I have an existing regex for email addresses as follows. ^(?=.*@.*\.)(?!.*@.*@)(?!.*[/|\\;,<>\s]).+$. I need to modify this regex to restrict all the special sequences being referred in Q3 above. (<!, &#, script:, expression(, " on... ="). Please help me with this.

    I know these are lot of questions. I do not have words to appreciate your help in this. The reason for questions Q1 - Q3 is so that I can learn this a little better and I can make some variations on my own. 

     Regards and thanks in advance

    -Arun

     

  •  09-10-2008, 5:35 PM 46222 in reply to 46215

    Re: Request for a new complex regex

    Q1:Yes.

    Q2:(?=.*(?:<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=))

    Q3:(?=.*(?:["| ]|<!|expression\(|<[^>]*>|&#|script:|on[a-z]+=))

    Q4:^(?=.*@.*\.)(?!.*(?:.*@.*@|[/"|\\;,\s<>]|expression\(|&#|script:|on[a-z]+=)).+$ with the extra items removed/combined, although since you disallow <> with the rule, the script, on...= are all probably extra to the pattern since they wouldn't be useful without an HTML tag of some sort <>.


  •  09-11-2008, 5:14 PM 46264 in reply to 46222

    Re: Request for a new complex regex

    Thanks Again for your help.

    -Arun

     

View as RSS news feed in XML