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
Post a Comment