例子: 这只是一个简单的句子。
我想匹配这句话和句子之间的每个字符。换行符应该被忽略。我想不出正确的语法。
例子: 这只是一个简单的句子。
我想匹配这句话和句子之间的每个字符。换行符应该被忽略。我想不出正确的语法。
当前回答
用这个:(?=开始名)(?=结束名)
其他回答
用这个:(?=开始名)(?=结束名)
有一种方法来处理在文本块中这种分裂的重复实例?例如:“这只是一个简单的句子。这里还有一些额外的东西。这只是一个简单的句子。这里还有一些东西。这只是一个简单的句子。”。要匹配每个实例而不是整个字符串,使用下面的代码:
data = "This is just\na simple sentence. Here is some additional stuff. This is just\na simple sentence. And here is some more stuff. This is just\na simple sentence."
pattern = re.compile('This is (?s).*? sentence')
for match_instance in re.finditer(pattern, data):
do_something(match_instance.group())
试试This is[\s\ s]*?句子,工作在javascript
我有这个字符串
headers:
Date:
schema:
type: string
example: Tue, 23 Aug 2022 11:36:23 GMT
Content-Type:
schema:
type: string
example: application/json; charset=utf-8
Transfer-Encoding:
schema:
type: string
example: chunked
Connection:
schema:
type: string
example: keep-alive
Content-Encoding:
schema:
type: string
example: gzip
Vary:
schema:
type: string
example: Accept-Encoding
Server:
schema:
type: number
example: Microsoft-IIS/10.0
X-Powered-By:
schema:
type: string
example: ASP.NET
Access-Control-Allow-Origin:
schema:
type: string
example: '*'
Access-Control-Allow-Credentials:
schema:
type: boolean
example: 'true'
Access-Control-Allow-Headers:
schema:
type: string
example: '*'
Access-Control-Max-Age:
schema:
type: string
example: '-1'
Access-Control-Allow-Methods:
schema:
type: string
example: GET, PUT, POST, DELETE
X-Content-Type-Options:
schema:
type: string
example: nosniff
X-XSS-Protection:
schema:
type: string
example: 1; mode=block
content:
application/json:
并且我想删除从单词headers:到content的所有内容,所以我写了这个正则表达式(headers:)[^]*?(content)
结果和预期的一样,这个表达式出现了多少次。
你可以简单地使用这个:\ this is .*?\句子