Is there any implementation of regex that allow to replace group in regex with lowercase version of it?
which of course doesn't work for international characters..
Anders Westrup
2009-01-09 11:01:58
The [A-Z]? It was an example. That said, I voted for j_random_hacker's answer.
Hank Gay
2009-01-09 11:10:57
+2
A:
Most Regex implementations allow you to pass a callback function when doing a replace, hence you can simply return a lowercase version of the match from the callback.
AnthonyWJones
2009-01-09 10:50:39
+3
A:
In Perl, you can do:
$string =~ s/(some_regex)/lc($1)/ge;
The /e
option causes the replacement expression to be interpreted as Perl code to be evaluated, whose return value is used as the final replacement value. lc($x)
returns the lowercased version of $x
. (Not sure but I assume lc()
will handle international characters correctly in recent Perl versions.)
/g
means match globally. Omit the g
if you only want a single replacement.
j_random_hacker
2009-01-09 11:08:12
+1
A:
If your regex version supports it, you can use \L, like so in a POSIX shell:
sed -r 's/(^.*)/\L\1/'
kimsnarf
2009-05-15 19:45:10