Add string after x characters

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
crazyelk
Forum Newbie
Posts: 2
Joined: Mon Jan 12, 2009 3:57 am

Add string after x characters

Post 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
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: Add string after x characters

Post by mintedjo »

Code: Select all

preg_replace("/\\\u(.{4})/","ZZZZ$1;",$str);
?
crazyelk
Forum Newbie
Posts: 2
Joined: Mon Jan 12, 2009 3:57 am

Re: Add string after x characters

Post by crazyelk »

WHOOHOOO :drunk:

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

thanks man!
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: Add string after x characters

Post by mintedjo »

WOOHOO!
I'm a heeero!
Post Reply