public static String findEscapedSpaceWordCloseToEnd ( String text ) { int index ; String originalText = text ; while ( ( index = text . lastIndexOf ( SPACE ) ) > - 1 ) { if ( index > 0 && text . charAt ( index - 1 ) == BACK_SLASH ) { text = text . substring ( 0 , index - 1 ) ; } else return originalText . substring ( index + 1 ) ; } return originalText ; }
Search backwards for a non - escaped space and only return work containing non - escaped space