Hi I need a regex which should match the following criteria
1. input string should not contain < followed by >
2. input string should not contain white spaces.
So the regular expression should return false, if the input string contains <something> pattern or spaces.
Ex:
!@~#$%^&*()_+ - true
<dsf adfas df> - false
sdf<sdsdf>sdf - false
dfs<sdf sdf > -false
asdf adf saf - false
sdafasf - true
<sd^&@*#)@) - true
<*&&*(_)#(&$)> - false
&$*(&<DS(^(*>SD^(+ - false
Thanks
Need a Regex
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Need a Regex
If it matches ".*(<[^>]*>|\s).*" it's invalid. In Java:
Code: Select all
String[] tests = {
"!@~#$%^&*()_+", // - true
"<dsf adfas df>", // - false
"sdf<sdsdf>sdf", // - false
"dfs<sdf sdf >", // - false
"asdf adf saf", // - false
"sdafasf", // - true
"<sd^&@*#)@)", // - true
"<*&&*(_)#(&$)>", // - false
"&$*(&<DS(^(*>SD^(+", // - false
};
for(String t: tests) {
System.out.println(!t.matches(".*(<[^>]*>|\\s).*")+"\t\t"+t);
}