天道酬勤,学无止境

ends-with

匹配不以空格开头或结尾的字符串的正则表达式(Regular Expression To Match String Not Starting With Or Ending With Spaces)

问题 我需要一个正则表达式来确保字符串不以空格开头或结尾。 我不在乎它在“中间”是否有空格,只是不在开头或结尾。 我有一个几乎有效的正则表达式: ^\S.*\S$ 以下是一些示例结果: "HELLO" (Match) "HEL LO" (Match) " HELLO" (No Match) "HELLO " (No Match) "H" (No Match) 如您所见,我遇到的问题是,当字符串只有 1 个字符长(上例中的“H”)时,它不会返回匹配项。 如何修改我的正则表达式来处理字符串长度为 1 的情况? 谢谢 注意 - 我将此数据保存到 Xml 文件中,因此我需要一个模式来匹配 Xml 模式中的相同内容。 我不确定它是否与 C# 中使用的任何正则表达式相同。 如果有人可以为我提供在我的架构中使用的模式,将不胜感激! 回答1 你可以这样做: ^\S(.*\S)?$ 它将匹配单个非空格字符,后跟可选的零个或多个字符,后跟单个非空格字符。 更新 鉴于您说这是用于 XML 模式验证,我使用此模式对其进行了测试: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="xml"> <xs:complexType> <xs:sequence> <xs:element name="test"

2021-06-10 12:34:38    分类:技术分享    c#   regex   whitespace   startswith   ends-with

How to determine if a string “ends with” another string in R?

I want to filter out the rows of a table which contain '*' in the string value of the column. Checking just that column. string_name = c("aaaaa", "bbbbb", "ccccc", "dddd*", "eee*eee") zz <- sapply(tx$variant_full_name, function(x) {substrRight(x, -1) =="*"}) Error in FUN(c("Agno I30N", "VP2 E17Q", "VP2 I204*", "VP3 I85F", "VP1 K73R", : could not find function "substrRight" The 4th value of zz should be TRUE by this. in python there is endswith function for strings [ string_s.endswith('*') ] Is there something similar to that in R ? Also, is it problem because of '*' as a character as it means

2021-06-05 02:09:27    分类:问答    r   string   ends-with

r dplyr ends_with multiple string matches

Can I use dplyr::select(ends_with) to select column names that fit any of multiple conditions. Considering my column names, I want to use ends with instead of contains or matches, because the strings I want to select are relevant at the end of the column name, but may also appear in the middle in others. For instance, df <- data.frame(a10 = 1:4, a11 = 5:8, a20 = 1:4, a12 = 5:8) I want to select columns that end with 1 or 2, to have only columns a11 and a12. Is select(ends_with) the best way to do this? Thanks!

2021-06-02 04:12:16    分类:问答    r   select   dplyr   string-matching   ends-with

在Java中使用startsWith和endsWith时,如何忽略大小写? [复制](How do I ignore case when using startsWith and endsWith in Java? [duplicate])

问题 这个问题已经在这里有了答案: 如何使用`string.startsWith()`方法忽略大小写? (7个答案) 3年前关闭。 这是我的代码: public static void rightSel(Scanner scanner,char t) { /*if (!stopping)*/System.out.print(": "); if (scanner.hasNextLine()) { String orInput = scanner.nextLine; if (orInput.equalsIgnoreCase("help") { System.out.println("The following commands are available:"); System.out.println(" 'help' : displays this menu"); System.out.println(" 'stop' : stops the program"); System.out.println(" 'topleft' : makes right triangle alligned left and to the top"); System.out.println(" 'topright' : makes right triangle alligned right and to

2021-05-31 22:54:10    分类:技术分享    java   string   case-insensitive   startswith   ends-with

Xpath“结束于”不起作用(Xpath “ends-with” does not work)

问题 我正在尝试找到一个动态ID名称总是以“ register”结尾的输入元素。 到目前为止,我已经尝试过 "//input[@id[ends-with(.,'register')]]" 和这个 "//input[ends-with(@id,'register')]" 这些都不会导致元素。 我究竟做错了什么? 同时,这可行: "//input[@id[contains(.,'register')]]" 这是来源的一部分: <td class="input"> <input id="m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register" name="m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register" class="aranea-checkbox" type="checkbox"> </td> 回答1 ends-with函数是xpath 2.0的一部分,但是浏览器(您表示您正在使用chrome测试)通常仅支持1.0。 因此,您必须自己结合使用string-length , substring和equals来实现它 substring(@id, string-length(@id) - string-length('register') +1) = 'register'

2021-05-25 00:51:37    分类:技术分享    xpath   ends-with

Regular Expression To Match String Not Starting With Or Ending With Spaces

I need a regular expression that makes sure a string does not start with or end with a space. I don't care if it has a space in the "middle" just not at the beginning or the end. I have a regular expression that almost works: ^\S.*\S$ Here are some example results: "HELLO" (Match) "HEL LO" (Match) " HELLO" (No Match) "HELLO " (No Match) "H" (No Match) As you can see, the issue I am having is that when the string is only 1 character long ("H" in the example above) it doesn't return a match. How do I modify my regular expression to handle the case where the string length is 1? Thank you NOTE - I

2021-05-11 04:18:06    分类:问答    c#   regex   whitespace   startswith   ends-with

AT命令响应(了解Arduino上代码执行的顺序)(AT command responses (understanding order of code execution on Arduino))

问题 我正在从Arduino Uno / Nano(ATmega328)向ESP8266发送AT命令,并尝试解析接收到的字符串的结尾以响应,以建立ESP的反应方式以及它是否成功(以及是否准备好接收另一个命令)然而)。 我知道在这里之前已经讨论了解析AT命令响应: 获取AT命令响应 但是我有一个没有解决的特定问题,这里的其他人也可能会感兴趣... 首先,调用一个函数,该函数将AT命令发送到ESP以连接到ThingSpeak(数据记录服务器)。 这在手动模式下可以正常工作,并且在尝试解析响应时也可以连接,但是它仅解析返回的第一行。 例如,串行监视器中的预期输出为: c AT+CIPSTART="TCP","api.thingspeak.com",80 CONNECT OK Connected to ThingSpeak! 其中c只是我键入的命令字符以启动连接。 但是,实际响应如下: c AT+CIPSTART="TCP","api.thingspeak.com",80 Cannot connect to ThingSpeak! CONNECT OK 这意味着解析函数在收到响应之前就结束了...如下代码所示,当前指定了10秒的超时时间。 即使超时20秒,也会发生相同的事情,尽管实际上在手动执行时,响应会在大约一秒钟后到达。 仅为了测试解析功能,我尝试搜索"80" ,它返回true

2021-05-09 17:30:41    分类:技术分享    c   arduino   at-command   ESP8266   ends-with

How do I ignore case when using startsWith and endsWith in Java? [duplicate]

This question already has answers here: How to use `string.startsWith()` method ignoring the case? (7 answers) Closed 3 years ago. Here's my code: public static void rightSel(Scanner scanner,char t) { /*if (!stopping)*/System.out.print(": "); if (scanner.hasNextLine()) { String orInput = scanner.nextLine; if (orInput.equalsIgnoreCase("help") { System.out.println("The following commands are available:"); System.out.println(" 'help' : displays this menu"); System.out.println(" 'stop' : stops the program"); System.out.println(" 'topleft' : makes right triangle alligned left and to the top")

2021-04-26 14:32:40    分类:问答    java   string   case-insensitive   startswith   ends-with

R是否具有像python一样的开头或结尾函数? [关闭](Does R have function startswith or endswith like python? [closed])

问题 关门了。 这个问题需要细节或明确性。 它当前不接受答案。 想改善这个问题吗? 添加详细信息,并通过编辑此帖子来澄清问题。 4年前关闭。 改善这个问题 > startsWith('abc', 'a') [1] TRUE > startsWith('abc', 'c') [1] FALSE > endsWith('abc', 'a') [1] FALSE > endsWith('abc', 'c') [1] TRUE 回答1 不是那种内在的。 选项包括grepl和substr 。 x <- 'ABCDE' grepl('^AB', x) # starts with AB? grepl('DE$', x) # ends with DE? substr(x, 1, 2) == 'AB' substr('ABCDE', nchar(x)-1, nchar(x)) == 'DE' 回答2 正如在3.3.0中添加到base中的那样, startsWith (和endsWith )就是这个。 > startsWith("what", "wha") [1] TRUE > startsWith("what", "ha") [1] FALSE https://stat.ethz.ch/R-manual/R-devel/library/base/html/startsWith.html 回答3

2021-04-11 20:12:13    分类:技术分享    python   r   string   startswith   ends-with

XPath testing that string ends with substring?

Given that the HTML contains: <div tagname="779853cd-355b-4242-8399-dc15f95b3276_Destination" class="panel panel-default"></div> How do we write the following expression in XPath: Find a <div> element whose tagname attribute ends with the string 'Destination' I've been searching for days and I can't come up with something that works. Among many, I tried for example: div[contains(@tagname, 'Destination')]

2021-04-05 04:23:39    分类:问答    html   xml   xpath   ends-with