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

Need your help (POSIX C)

Last post 01-30-2008, 1:47 AM by Stevezilla00. 5 replies.
Sort Posts: Previous Next
  •  01-28-2008, 10:38 PM 39022

    Need your help (POSIX C)

    Dear all,

    I have a question need your help (POSIX regex). the question is shown as following.

    There are several specified realms, and now there is a user which name likes abc@realm.com,

    we should check if the realm of the use was not included in those realms.
    Example:
    The realms includes @cnn.com, @mil.gov, @blackberry.com, @yahoo.com and @abc.net, now there is a use user@realm.com,
    I want to get the result that the realm of
    user@realm.com is not included in above realms.

    Thanks.

    user@realm.com is not included in above realms.

    Thanks.

    Thanks.

  •  01-29-2008, 5:53 PM 39067 in reply to 39022

    Re: Need your help (POSIX C)

    If I understand your question, and given the (severe) limitations of POSIX, you could try something like:

    @(cnn.com|mil.gov|blackberry.com|yahoo.com|abc.net)$

    and then check that your pattern does NOT match your text.

    I think you are trying to see if a given email-like address is being sent to one of a special set of addresses and stop it if it is. What I'm proposing is, rather than looking at creating a pattern to match allowed addresses, create one to match the forbidden addresses and allow the email if there is no match.

    The advantage of this is that it is quite easy to add (or remove) items from the alternation as new addresses are forbidden. However, there is an (almost) infinite number of allowable addresses.

    Susan 

  •  01-29-2008, 5:55 PM 39069 in reply to 39022

    Re: Need your help (POSIX C)

    There are two POSIX regex flavors (BRE and ERE) which have different features and use different syntax. In any case, although you could solve this with a regex it would probably be better not to. Here's an example of how it could be done using JavaScript 1.6+:

    var user = "abc@realm.com";
    var realms = ["cnn.com","mil.gov","blackberry.com","yahoo.com","abc.net"];
    var isValidRealm = realms.indexOf(user.slice(user.indexOf("@") + 1)) > -1;
    // isValidRealm == false


    My regex-centric blog :: JavaScript regex tester
  •  01-30-2008, 1:41 AM 39084 in reply to 39067

    Re: Need your help (POSIX C)

    Hi Susan

    Thanks for you quick response. yes, you are fully correct.

    I can get the positive result  "^.*?@(cnn\.com|mil\.gov|blackberry\.com|yahoo\.com|abc\.net)?$"

  •  01-30-2008, 1:44 AM 39085 in reply to 39069

    Re: Need your help (POSIX C)

    Thanks Steve, there was not any API.
  •  01-30-2008, 1:47 AM 39087 in reply to 39084

    Re: Need your help (POSIX C)

    Lazy quantifiers like *? are certainly not part of either of the two POSIX regex flavors.

    My regex-centric blog :: JavaScript regex tester
View as RSS news feed in XML