I want to check if a string contains exactly 1 alphabetic char, that may or may not be preceded by any of ~, ! or ?. The expression I have set to match against is:
if (this.str.matches("[!~?]{1,9}?[a-z]{1}")) {
but when the input I have (this.str) is equal to 'p', this if block is not triggered. What am I doing wrong?
Some strings that should match:
!!~?p
p
~p
???!!?!??!~p
Thanks heaps :)
!,~and?) can be optional (can be absent), use"[!~?]{0,9}[a-z]". Or even"[!~?]*[a-z]"where*means 0 or more occurrences.~!???~~!!xbe valid? If the "alphabetic char" can only preceded by 1 character, use"[!~?]?\\p{L}", where\\p{L}means any Unicode letter, not just a-z.