开发者

Find text between a Char

I want to use regex to replace some custom place holders in a text file, the file looks like this:

I am %name% the %profession%...

(it s开发者_C百科hould be replaced for example with "I am Ronald the Clown")

Right now I am using following regex to replace the place holders:

(%.*%)

it finds everything between the %-mark:

%name%
% the %
%profession%

obviously I want to ignore "% the %".. Any idea how to accomplish this? I could do this without regex but maybe there is a way with regex?

Thanks!


You could try this:

%([^ %]+)%

[^ %] will match anything but a space or a percent sign (if you're using variables without spaces as I hope).

EDIT: \b didn't work, sorry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜