Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible with regular expressions?

Tags:

regex

replace

Something like this:

/[abcd]/[efgh]/

The idea is that a will get replaced with e, b with f, c with g and so on.

Ideally, this should be language independent. If that isn't possible, I have an alternate solution (because this regex is generated by some code, I can make one for each of the possible replacements).

like image 781
Javier Avatar asked Nov 21 '25 08:11

Javier


2 Answers

In perl, tr performs character replacement:

tr/abcd/efgh/

Will do what your example suggests.

like image 162
Anon. Avatar answered Nov 23 '25 23:11

Anon.


In sed, the y/// expression does just that.

It's also a synonym for tr/// in perl

like image 39
Matt Stephenson Avatar answered Nov 23 '25 23:11

Matt Stephenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!