split 相关问题

使用此标记可以解决有关将项目(例如字符串)分成多个部分的问题,通常是通过分隔符或正则表达式。

PHP:将一根字符串分为char

无论我在动作脚本中做过类似的事情,但无法弄清楚在PHP中如何称呼它。我找不到将单词的每个字符都放在数组中的方法。

回答 4 投票 0



如何将一根字符串分成2的块,但要做最后一个块3,如果是1

我有一系列不同的长度字符串,我需要将其分成2个字符的块。最后一个块应该长3个字符,如果要长1个字符。 例如,

回答 0 投票 0

Python:使用split()在2个单独的点上拆分字符串

我有一个我需要在2个单独的部分中拆分的字符串,但是我发现的只是如何使用标识符和其他标点等标识符分开字符串。 string = "<p>The brown dog jumped over the... <a href="https://google.com" target="something">... but then splashed in the water<p> hyperlink = re.split(r'(?=https)',string) print(hyperlink[0]) 在上面的示例中,我需要在字符串“ https://google.com”中提取URL,然后打印出。但是,我只能找出如何在“ https”上拆分字符串,因此随之而来的所有内容都随附。 我希望这是有道理的。经过一堆搜索和测试后,我可以弄清楚如何做到这一点。 可以实现多种方法,但是一个简单的方法是使用find()然后切片。 find()将在字符串中找到子字符串的起始位置。然后,您可以将其切成薄片。 例如 string = '<p>The brown dog jumped over the... <a href="https://google.com" target="something">... but then splashed in the water<p>' # Find where the URL starts start_word = "https" start_index = string.find(start_word) # For URLs, we need to find where it ends - usually at a quote mark end_index = string.find('"', start_index) # Extract just the URL result = string[start_index:end_index] print(result) 输出: "https://google.com" 方法返回基因开始的索引。然后,使用这些位置,我们将字符串切成薄片以提取我们想要的部分。 将有各种正则表达式和re模块的功能可以实现您的目标。 there是一个: find() 输出: import re string = '<p>The brown dog jumped over the... <a href="https://google.com" target="something">... but then splashed in the water<p>' m = re.findall(r'^.*href="(.*)"\s.*$', string) print(*m) 如果您不想使用re然后: https://google.com ...将给出相同的输出。 有人建议在Commen中建议您使用模块来解析或kw = 'href="' start = string.find(kw) + len(kw) end = string[start:].find('"') result = string[start : end + start] print(result) 像xml或html-有时是更简单的方法。 lxm pyparsing创建以匹配HTML标签的解析器表达式避免了使用Regex等工具来解析HTML的许多经典问题: handles案例不敏感(标签和标签属性名称) handles引用和未引用的属性值 取回封闭标签(以'/'结尾的打开标签) ignores嵌入了空格 在这种情况下,我们只需要搜索一个标签,然后让pyparsing抓住标签属性,如解析结果上的属性: BeautifulSoup

回答 4 投票 0



划分样品分裂 我正在与来自174名受试者的数据一起工作,该数据存储在数据框架(DF_BEHAVIORAL)中,其中一排代表一个主题。某些受试者彼此相关,如一个称为“

到目前为止,这是我的代码。我能够收到两个无关的受试者子样本,但仍需要帮助通过神经质得分实施分层。

回答 0 投票 0

如何从两个不同的列中拆分多值,并从一个列显示拆分值与另一列的拆分值?

我有两列,如下: repay_aount repay_ref 150.063829.07 T21Q1P-20210529T21XYN-20210428 160.1216502429.49 T21YMG-20210628T21GVX-20210531T21Q1P-20210529 115.9104.2826001461.47

回答 1 投票 0

我的string.split()

IAM AM将方程式字符串分为类似的字符串数组: string [] equation_array =(equation.split(“(?<=[-+×÷)(])|(?=[-+×÷)(])")); Now for test string: test = "4+(2×5)" result is fine:

回答 4 投票 0

基于字符的拆分创建嵌套列表

我有一个由字符串列出的列表,正确清洁(可以安全地使用(',')),并根据数字正确排序。作为一个小例子: l = ['c1','c1,c2','c2,c3','c3,c4','c4','c5','c ...

回答 2 投票 0



在R

我有一个列表

回答 1 投票 0


如何将字符串拆分到由支架包裹的子字样?

我有这样的字符串 [ABC] [DEF] 我已经实施了以下代码来解析它: val匹配:mutableList= mutableListof() val str =“ [abc] [def]” val matcher = tatter.co ...

回答 1 投票 0





最新问题
© www.soinside.com 2019 - 2025. All rights reserved.