开发者

Find text between a Char

开发者 https://www.devze.com 2023-02-18 09:21 出处:网络
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%...

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

精彩评论

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