Regex to fetch a line by the matching the last word , but the lastword should not be selected -


i need regular expression needs fetch line has 1 matching word @ end. should select line without selecting lastword.

for e.g

abc = new obj(); //object object_creation

regex should select above statement has object_creation @ end should select upto below one. object_creation keyword should used identify line , should not selected.

expected output

abc = new obj(); //object

is possible that?

just replace last word along preceding space character empty string.

string.replaceall("\\s*\\s+$", ""); 

or

string.replaceall("\\s*\\s+\\s*$", ""); 

or

matche chars upto last space.

pattern p = pattern.compile(".*(?= )"); 

or

pattern p = pattern.compile(".*(?=\\s)"); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -