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.
精彩评论