regex

get specific character

佐手、 提交于 2021-01-01 03:52:58
问题 I would like to remove Zero from a string, below is an example : String a : 020200218-0PSS-0010 a.replaceall("-(?:.(?!-))+$", "**REPLACEMENT**") Actual : 020200218-0PSS-0010 Expected : 020200218-0PSS-10 I'm using this regex to catch -0010 : -(?:.(?!-))+$ I just dont know what to do in the REPLACEMENT section to actually remove the unused zero (not the last zero for exemple "10" and not "1") Thanks for reading! 回答1: You could use something like: (?<=-)0+(?=[1-9]\d*$) It translates to "find all

get specific character

浪尽此生 提交于 2021-01-01 03:51:37
问题 I would like to remove Zero from a string, below is an example : String a : 020200218-0PSS-0010 a.replaceall("-(?:.(?!-))+$", "**REPLACEMENT**") Actual : 020200218-0PSS-0010 Expected : 020200218-0PSS-10 I'm using this regex to catch -0010 : -(?:.(?!-))+$ I just dont know what to do in the REPLACEMENT section to actually remove the unused zero (not the last zero for exemple "10" and not "1") Thanks for reading! 回答1: You could use something like: (?<=-)0+(?=[1-9]\d*$) It translates to "find all

Dynamic value for max length in a regex

廉价感情. 提交于 2021-01-01 02:27:53
问题 i need to validate differents input value lengths. Inputs value can have a max length of 6 / 15 / 25 characters. Now i was asking to my self if it's a good practice use only one dynamic regex to validate differents max lengths, instead of copy paste the same regex. During my research i found that i've to use the the const regex = new RegExp() the problem is that i tried const lengthValidation = () => { const maxLength = 4; const inputValue = 'ciao'; const regex = new RegExp(`/^.{6,${maxLength

Dynamic value for max length in a regex

谁说胖子不能爱 提交于 2021-01-01 02:16:35
问题 i need to validate differents input value lengths. Inputs value can have a max length of 6 / 15 / 25 characters. Now i was asking to my self if it's a good practice use only one dynamic regex to validate differents max lengths, instead of copy paste the same regex. During my research i found that i've to use the the const regex = new RegExp() the problem is that i tried const lengthValidation = () => { const maxLength = 4; const inputValue = 'ciao'; const regex = new RegExp(`/^.{6,${maxLength

Linux-----sed 命令详解

家住魔仙堡 提交于 2020-12-31 14:18:26
Linux-----sed 命令详解 sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换、删除、新增、选取等特定工作,下面先了解一下sed的用法 sed命令行格式为: ====================================================================================== 常用选项: -n∶使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN的资料一般都会被列出到萤幕上。但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作)才会被列出来。 -e∶直接在指令列模式上进行 sed 的动作编辑; -f∶直接将 sed 的动作写在一个档案内, -f filename 则可以执行 filename 内的sed 动作; -r∶sed 的动作支援的是延伸型正规表示法的语法。(预设是基础正规表示法语法) -i∶直接修改读取的档案内容,而不是由萤幕输出。 常用命令: a ∶新增, a 的后面可以接字串,而这些字串会在新的一行出现(目前的下一行)~ c ∶取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行! d ∶删除,因为是删除啊,所以 d 后面通常不接任何咚咚; i ∶插入, i 的后面可以接字串,而这些字串会在新的一行出现

Regex match ordering

只谈情不闲聊 提交于 2020-12-31 05:29:42
问题 My question is simple suppose I would like to match the vowels in a word, but I would like to match them in a specific order as the appear such as a, e, i, o, u. How would I go about doing this? 回答1: So you're looking for a followed by some characters, then e followed by some characters, and so forth? In other words, a followed by stuff that isn't e , then e . Then stuff that isn't i then i . Then stuff that isn't o then o . And finally stuff that isn't u and lastly a u . In regexp terms,

Regex match ordering

≡放荡痞女 提交于 2020-12-31 05:28:19
问题 My question is simple suppose I would like to match the vowels in a word, but I would like to match them in a specific order as the appear such as a, e, i, o, u. How would I go about doing this? 回答1: So you're looking for a followed by some characters, then e followed by some characters, and so forth? In other words, a followed by stuff that isn't e , then e . Then stuff that isn't i then i . Then stuff that isn't o then o . And finally stuff that isn't u and lastly a u . In regexp terms,

Regex match everything except words between quotes

心已入冬 提交于 2020-12-31 05:12:21
问题 I want to write a regex what matches everything except words between quotes. Ex.: Lorem ipsum "dolor" sit amet, consectetur "adipiscing" elit. Nunc ultrices varius odio, "ut accumsan nisi" aliquet vitae. "Ut faucibus augue tortor, at aliquam purus dignissim eget." So I want a regex what matches the following strings: Lorem ipsum sit amet, consectetur elit. Nunc ultrices varius odio, aliquet vitae. I only have the following expression that matches substrings inside quotes: ([\"'])(?:\\\1|.)*?

Regex match everything except words between quotes

谁说我不能喝 提交于 2020-12-31 05:09:57
问题 I want to write a regex what matches everything except words between quotes. Ex.: Lorem ipsum "dolor" sit amet, consectetur "adipiscing" elit. Nunc ultrices varius odio, "ut accumsan nisi" aliquet vitae. "Ut faucibus augue tortor, at aliquam purus dignissim eget." So I want a regex what matches the following strings: Lorem ipsum sit amet, consectetur elit. Nunc ultrices varius odio, aliquet vitae. I only have the following expression that matches substrings inside quotes: ([\"'])(?:\\\1|.)*?

Regex match everything except words between quotes

試著忘記壹切 提交于 2020-12-31 05:09:56
问题 I want to write a regex what matches everything except words between quotes. Ex.: Lorem ipsum "dolor" sit amet, consectetur "adipiscing" elit. Nunc ultrices varius odio, "ut accumsan nisi" aliquet vitae. "Ut faucibus augue tortor, at aliquam purus dignissim eget." So I want a regex what matches the following strings: Lorem ipsum sit amet, consectetur elit. Nunc ultrices varius odio, aliquet vitae. I only have the following expression that matches substrings inside quotes: ([\"'])(?:\\\1|.)*?