Filter wrong characters from android package name using regex -


i want filter wrong characters string (and replace them empty string later). tried making own regex expression have not succeeded make working. need javascript support.

desired effect: com.12%example%.5a5pp => com.example.a5pp (regex matches: [1,2,%,%,5]).

you can find package name requirements here:

a full java-language-style package name android application. name should unique. name may contain uppercase or lowercase letters ('a' through 'z'), numbers, , underscores ('_'). however, individual package name parts may start letters.

i'm more familiar ruby myself, believe android apps written in java, , java can (?<) look-behinds. on assumptions, regex match incorrect character:

/[^\w.]|(?<=^|\.)[^a-za-z]+/g 

you can plug 'replace' method replace match empty string.

(regex 101 place find meaning of each component of regex.)


[update] javascript, doesn't support look-behinds, you'd have capture dot (if there one) in group able put back:

/[^\w.]|(^|\.)[^a-za-z]+/g 

instead of empty string, replace '$1' (which represents captured dot).


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -