小编Sha*_*ark的帖子

正则表达式检测不在{}之间的所有内容然后从匹配的搜索中搜索

我对stackoverflow和Regex都很新,所以请原谅我的错误.

我一直在寻找一个正则表达式来匹配所有不在花括号{}之间的文本,并从该文本中找到某些单词.例如,从以下字符串:

$content = 'Hello world, { this } is a string with { curly brackets } and this is for testing'

我想搜索单词this只返回第二次出现,this因为它在不在花括号内的区域.即使我可以使用正则表达式匹配大括号外的子串,我也会简化一些事情.我发现这个正则表达式,/(}([^}]*){)/但它不能选择部分Hello world,, and this is for testing因为它们不在里面}{,它只选择is a string with部分.

另外我想问一下是否可以将两个正则表达式组合起来用于像我这样的单一目的.例如,第一个Regex在外部查找字符串{},第二个查找搜索的特定单词.

我想在php中使用这个正则表达式,现在我使用的函数更像是一个黑客.目的是找到不在的特定单词,{}可靠地替换它们并写入文本文件.

在此先感谢您的帮助.

php regex

7
推荐指数
1
解决办法
269
查看次数

芹菜泡菜类型内容不允许出错

即使我在settings.py中有以下行:

CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASKS_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
from kombu import serialization
serialization.registry._decoders.pop("application/x-python-serialize")
Run Code Online (Sandbox Code Playgroud)

我仍然得到不允许追溯的泡菜内容.奇怪的是,我已经有芹菜在另一个地方完全相同的设置工作正常.如果有人可以提出解决方案,那将非常有帮助.Django版本是1.7.1,芹菜今天下载,所以应该是最新的.使用rabbitmq作为经纪人.以下是错误的完整回溯.

[2015-01-01 23:45:20,652: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed('Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)',) [type:u'application/x-python-serialize' encoding:u'binary' headers:{}]
body: '\x80\x02}q\x01(U\x07expiresq\x02NU\x03utcq\x03\x88U\x04argsq\x04X\x04\x00\x00\x00dsgfq\x05\x85q\x06U\x05chordq\x07NU\tcallbacksq\x08NU\x08errbacksq\tNU\x07tasksetq\nNU\x02idq\x0bU$76263889-0ef2-4193-8286-1a38630df08aq\x0cU\x07retriesq\rK\x00U\x04taskq\x0eU"pricematch.tasks.amazon_pricematchq\x0fU\ttimelimitq\x10NN\x86U\x03etaq\x11NU\x06kwargsq\x12}q\x13u.' (241b)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 586, in _receive_callback
    decoded = None if on_m else message.decode()
  File "/usr/local/lib/python2.7/dist-packages/kombu/message.py", line 142, in decode
    self.content_encoding, accept=self.accept)
  File "/usr/local/lib/python2.7/dist-packages/kombu/serialization.py", line 174, in loads
    raise self._for_untrusted_content(content_type, 'untrusted')
ContentDisallowed: Refusing to deserialize untrusted content of …
Run Code Online (Sandbox Code Playgroud)

python django rabbitmq celery

6
推荐指数
1
解决办法
3784
查看次数

标签 统计

celery ×1

django ×1

php ×1

python ×1

rabbitmq ×1

regex ×1