Reputation: 127
I am using regex for my sentence contains bullet space digit and dot.
• 1. This is sample Application
• 2. This is Sample java program
regex:
•\\s\\d\\.\\s[A-z]
Required output:
This is sample Application.
This is Sample java program.
its not working.Please Suggest me how to do this.
Upvotes: 7
Views: 16750
Reputation: 2053
Instead of using the actual 'bullet,' use the unicode equivalent:
\u2022\s\d\.\s[A-z]
For more info see Unicode Character 'BULLET' (U+2022) and Regex Tutorial - Unicode Characters and Properties
EDIT: To split the lines (assuming each line is a separate string) try this out:
String firstString = "• 1. This is sample Application"; System.out.println(firstString.split("\\u2022\\s\\d\\.\\s")[1]);
This works because String.split
cuts your string into an array wherever there's a match. The [1]
addresses the second item in that array, being the second half of the split.
Upvotes: 3
Reputation: 2058
To match the bullet character you will need to use the unicode escape sequence. However Unicode defines several bullet styles, so it's probably best to allow for all of them:
[\u2022,\u2023,\u25E6,\u2043,\u2219]\s\d\.\s[A-z]
This should match the following bullet styles:
Reference: https://en.wikipedia.org/wiki/%E2%80%A2
Upvotes: 15
Reputation: 2323
use this
String a="• 1. This is sample Application";
a = a.replaceAll("\\u2022(?=\\s\\d\\.\\s[A-z])",""); // this will remove the • if only the bulet have \\s\\d\\.\\s[A-z] patern after it.
System.out.println(a);
Upvotes: 1
Reputation: 35557
Why regex
? you can use this way
String str="• 1. This is sample Application";
String newStr=str.replaceAll("\\•|\\.","");
// Or str.replaceAll("\\u2022|\\.","");u2022 is unicode value of bullet
System.out.println(newStr);
Upvotes: 0