regex - RegExp Javascript HEX Colors Light and Dark -


i want use regular expression replace first f of each of 3 hex sets make hex color e.

ffffff become efefef

fefefe become eeeeee

you can use this:

str = str.replace(/f(?=[a-f0-9](?:[a-f0-9]{2}){0,2}$)/g, 'e'); 

pattern details:

f (?=         # lookahead assertion: means "followed by"             # trick use relative position end of string     [a-f0-9]  # hexadecimal character         (?:[a-f0-9]{2}){0,2} # number of hexadecimal characters $                        # until end )           # close lookahead assertion. 

note in lookahead checked, not part of match result. reason why replacement string e.


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -