Page 1 of 1

Add string after x characters

Posted: Mon Jan 12, 2009 4:17 am
by crazyelk
Hi,

I'm quite new to regex, and the following expression drives me nuts.

What I have: Entz\u00FCndung des Zw\u00F6lffingerdarms

Endokarditis
What I need: EntzZZZZ00FC;ndung des ZwZZZZ00F6;

lffingerdarms Endokarditis

The first part to replace "\u" with "ZZZZ" is not the problem, but how to add the ";" at the end of

the string.

I tried

preg_replace(/ZZZZ++++/, /ZZZZ++++;/)
preg_replace(/(ZZZZ++++)/, /(ZZZZ++++;)/)
preg_replace(/ZZZZ{0,4}/, /ZZZZ{0,4};/)

none of these works. :banghead:

It's always Searchstring + 4 character ADD string ;.

Please help.

Thanks a lot,
Chris

Re: Add string after x characters

Posted: Mon Jan 12, 2009 6:54 am
by mintedjo

Code: Select all

preg_replace("/\\\u(.{4})/","ZZZZ$1;",$str);
?

Re: Add string after x characters

Posted: Mon Jan 12, 2009 9:34 am
by crazyelk
WHOOHOOO :drunk:

mintedjo, you're definitly my hero of the week!

thanks man!

Re: Add string after x characters

Posted: Mon Jan 12, 2009 10:06 am
by mintedjo
WOOHOO!
I'm a heeero!