deleting the first word in a string
hi! i'm learning regex and with this code i would like to
1) print a string (from "Hi my name is SandraPandra. do not print this")
2) remove the first word and print the new, shorter string
3) remove the first word in the new, shorter string and print the newer and shorter string
4) continue this until it hits a non-character (e.g period, colon, quotation marks etc)
does anyone here know how i should change my code in order to achieve this?
here's my code:
class Testar{
publicstaticvoid main(String[] args){
String partDesc ="Hi my name is SandraPandra. do not print this.";
do{
System.out.println(partDesc);
partDesc = partDesc.replaceFirst("^(\\w+)\\s+","");}
while (partDesc.equals("\\w") ==true);
if (partDesc.equals("\\w") ==false){//this is where something goes wrong
System.out.println("found a full stop!");}
}
}
the outcome now is:
Hi my name is SandraPandra. do not print this.
found a full stop!
Thank you in advance!

