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

Need regex to omit <followedby> or white spaces

Last post 04-01-2008, 6:18 PM by Aussie Susan. 1 replies.
Sort Posts: Previous Next
  •  04-01-2008, 2:06 PM 40923

    Need regex to omit <followedby> or white spaces

    I am looking for a regular expression which should match the following criteria

    1. Input string should not contain <followed by>
    2. Input string should not contain white spaces.

    Below are the examples for which regex should return true/false (Regex.IsMatch(inputString))

    some<testhaspattern>thing - false
    s&*<te*&#df> - false
    test has space - false
    <test has space and pattern> - false
    test<test has space and pattern>test - false
    <testhaspattern> - false
    testhasnospace - true
    test*has&no#space - true
    test*has&no#spaces%and$special~charsare^ok - true

    So regex should return false if the input string contain <pattern> or white spaces or both. 

    Thanks in advance

    Filed under: ,
  •  04-01-2008, 6:18 PM 40936 in reply to 40923

    Re: Need regex to omit <followedby> or white spaces

    Try:

    ^(?![^\s]* )(?![^<\r]*<[^>\r]*>).*$

    with the multiline option set. 

    You don't tell us the language/regex you are using so I have no idea if  this will work for you.

    It matches all of the test cases you have provided. I have also added another which is:

    test>words<pattern

    for which it returns true, as do other test strings that contain only a < or a > but not both in that order.

    Susan 

View as RSS news feed in XML