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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -