java - Regex to replace all leading characters not a-Z -


i need replace non-letter characters appear @ start before letter example

$ %5hello w8r^ld becomes hello w8r^ld

this regex got works greate replacing none word characters not replace numbers

s.replacefirst("^[\\w_]+", "") 

you using wrong character class. use

s.replacefirst("^[^a-za-z]+", "") 

that is

^          start @ beginning of string [^  ]+     1 or more (greedy - keep going until hit letter a-za-z     ascii characters between a-z or a-z 

following comments @anubhava, changed * +. if have no match, there nothing needs replacing. it's cleaner.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -