本文由我司收集整编,推荐下载,如有疑问,请与我司联系
python中字符串是什么preg
preg_replace在省略时插入默认值[英]preg_replace to insert default value when omitted I’m trying to work on some regex for a preg_replace that would insert a default key=“value” when it is not in the subject.
我正在尝试为preg_replace工作一些正则表达式,当它不在主题中时会插入默认键=“值”wrapper”] but when there is a value, I don’t want it to match. This means that this: 但是当有价值时,我不希望它匹配。这意味着:
[section title=“This is the title” type=“full”] would stay the same.
会保持不变。
I am using the negative lookahead incorrectly. The first part will always match and the (?!type) becomes irrelevant. I’m not sure how to place it so that it would work. Any ideas? 我错误地使用了负面预测。第一部分将始终匹配,(?!类型)变得无关紧要。我不知道如何放置它以便它可以工作。有任何想法吗?
2
$your_variable = str_replace(‘type=“full” type=“wr = ‘ type=“wrapper”]’;echo preg_replace($pattern, $replacement, $subject); 1
I think you’re going about this the wrong way. Personally, I’d use preg_replace_callback to process it. Something like:
我认为你这是错误的做法。就个人而言,我会使用preg_replace_callback来[标签:内容]
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论