Replace all characters not in range (Java String)

两盒软妹~` 提交于 2019-11-28 20:20:14
tangens

To explain: The ^ at the start of a character class will negate that class But it has to be inside the class for that to work. The same character outside a character class is the anchor for start of string/line instead.

You can try this instead:

"[^0-9]"
polygenelubricants

Here's a quick cheat sheet of character class definition and how it interacts with some regex meta characters.

  • [aeiou] - matches exactly one lowercase vowel
  • [^aeiou] - matches a character that ISN'T a lowercase vowel (negated character class)
  • ^[aeiou] - matches a lowercase vowel anchored at the beginning of the line
  • [^^] - matches a character that isn't a caret/'^'
  • ^[^^] - matches a character that isn't a caret at the beginning of line
  • ^[^.]. - matches anything but a literal period, followed by "any" character, at the beginning of line
  • [a-z] - matches exactly one character within the range of 'a' to 'z' (i.e. all lowercase letters)
  • [az-] - matches either an 'a', a 'z', or a '-' (literal dash)
  • [.*]* - matches a contiguous sequence (possibly empty) of dots and asterisks
  • [aeiou]{3} - matches 3 consecutive lowercase vowels (all not necessarily the same vowel)
  • \[aeiou\] - matches the string "[aeiou]"

References

Related questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!