Wanna get only right content in java regex -


what have modify in code:

string tags = "<div class='bat'><div id='me'>"; pattern r = pattern.compile("<(.*)>",pattern.case_insensitive| pattern.multiline | pattern.dotall );  // create matcher object. matcher m = r.matcher(tags); while (m.find( )) {     system.out.println("found : " + m.groupcount() );     system.out.println(m.group());    } 

output :

found : 1 <div class='bat'><div id='me'> 

and want output :

found: 2 div class='bat' div id='me' 

you need ahead , behind this

i.e. (?<=<)([^>]*)(?=>)

string tags = "<div class='bat'><div id='me'>"; pattern r = pattern.compile("(?<=<)([^>]*)(?=>)", pattern.case_insensitive | pattern.multiline | pattern.dotall); 

output :

found : 1 div class='bat' found : 1 div id='me' 


edit replaced .*? [^>]* performance suggested pschemo


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -