javascript - regex: Match when between text but not between digits -
please help. need regular expression (to used in javascript) replace "." "#" in text containing unicode characters. replacement takes place when "." appears between text not between digits.
input: "ΦΨ. abc. def. 123.456"
desired output: "ΦΨ# abc# def# 123.456"
any suggestions?
you can use capturing groups in regex , use back-references obtain required result:
var re = /(\d)\.(\d)/g; var str = 'ΦΨ. abc. def. 123.456'; var subst = '$1#$2'; result = str.replace(re, subst); alert(result);
regex explanation:
\d
- non-digit character\.
- literal dot
the non-digit characters captured groups, , inserted of $1
, $2
back-references.
Comments
Post a Comment