regex - Rexexp to match all the numbers,alphabets,special characters in a string -



regex - Rexexp to match all the numbers,alphabets,special characters in a string -

i want pattern match string has in it(alphabets,numbers,special charactres)

public static void main(string[] args) {

string retval=null; seek { string s1 = "[0-9a-za-z].*:[0-9a-za-z].*:(.*):[0-9a-za-z].*"; string s2 = "bntpsdae31g:bntpsdae:healthcheck:major"; pattern pattern = null; //if ( ! stringutils.isempty(s1) ) if ( ( s1 != null ) && ( ! s1.matches("\\s*") ) ) { pattern = pattern.compile(s1); } //if ( ! stringutils.isempty(s2) ) if ( s2 != null ) { matcher matcher = pattern.matcher( s2 ); if ( matcher.matches() ) { retval = matcher.group(1); // special case/kludge asentria. temp alarms contain "normal/high" etc. // switch normal homecoming clear. default usage raise. // need handle switches in xml. won't work if puts "normal" in event alias. if ("restore".equalsignorecase ( retval ) ) { } } } } catch( exception e ) { system.out.println("error evaluating args : " ); } system.out.println("retval------"+retval);

}

and output is: healthcheck hera using [0-9a-za-z].* matching alpahbets , numbers,but want match string if has special characters also

any help highly appreciated

try this:

if want match individual elements seek this:

2.1.2 :001 > s = "asad3435@#:$%adasd1213" 2.1.2 :008 > s.scan(/./) => ["a", "s", "a", "d", "3", "4", "3", "5", "@", "#", ":", "$", "%", "a", "d", "a", "s", "d", "1", "2", "1", "3"]

or want match @ 1 time seek this:

2.1.2 :009 > s.scan(/[^.]+/) => ["asad3435@#:$%adasd1213"]

regex

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -