regex

grep lines that start with a specific string

こ雲淡風輕ζ 提交于 2021-02-05 00:56:30
问题 I want to find all the lines in a file that start with a specific string. The problem is, I don't know what's in the string beforehand. The value is stored in a variable. The naïve solution would be the following: grep "^${my_string}" file.txt; Because if the Bash variable my_string contains ANY regular expression special characters, grep will cry, and everyone will have a bad day. You don't want to make grep cry, do you? 回答1: You should use awk instead of grep for non-regex search using

Simplest way to get rid of zero-width-space in c# string

一个人想着一个人 提交于 2021-02-04 22:37:07
问题 I am parsing emails using a regex in a c# VSTO project. Once in a while, the regex does not seem to work (although if I paste the text and regex in regexbuddy, the regex correctly matches the text). If I look at the email in gmail, I see =E2=80=8B at the beginning and end of some lines (which I understand is the UTF8 zero width space); this appears to be what is messing up the regex. This seems to be only sequence showing up. What is the easiest way to get rid of this exact sequence? I cannot

Remove last char from result of a match regex

回眸只為那壹抹淺笑 提交于 2021-02-04 22:36:08
问题 I'm trying to extract a part of html in a jmeter test. I need to extract just a part from a <script src="" tag. full script src: <script src="/Paginas/Inicializacao/AguardarAcao.aspx?_TSM_HiddenField_=ctl00_ToolkitScriptManager1_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d1.0.11119.38311%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3apt-BR%3adf9c6e46-ef8c-4a3d-89af-f80adf22e9c2%3a865923e8%3a411fea1c%3ae7c87f07%3a91bd373d%3a1d58b08c%3a8e72a662

Look behinds: all the rage in regex?

╄→尐↘猪︶ㄣ 提交于 2021-02-04 22:35:48
问题 Many regex questions lately have some kind of look-around element in the query that appears to me is not necessary to the success of the match. Is there some teaching resource that is promoting them? I am trying to figure out what kinds of cases you would be better off using a positive look ahead/behind. The main application I can see is when trying to not match an element. But, for example, this query from a recent question has a simple solution to capturing the .* , but why would you use a

Remove last char from result of a match regex

萝らか妹 提交于 2021-02-04 22:35:16
问题 I'm trying to extract a part of html in a jmeter test. I need to extract just a part from a <script src="" tag. full script src: <script src="/Paginas/Inicializacao/AguardarAcao.aspx?_TSM_HiddenField_=ctl00_ToolkitScriptManager1_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d1.0.11119.38311%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3apt-BR%3adf9c6e46-ef8c-4a3d-89af-f80adf22e9c2%3a865923e8%3a411fea1c%3ae7c87f07%3a91bd373d%3a1d58b08c%3a8e72a662

How to use word break, asterisk, word break in Regex with Perl?

蹲街弑〆低调 提交于 2021-02-04 22:21:12
问题 I have a complexe precompiled regular expression in Perl. For most cases the regex is fine and matches everything it should and nothing it shouldn't. Except one point. Basically my regex looks like: my $regexp = qr/\b(FOO|BAR|\*)\b/; Unfortunately m/\b\*\b/ won't match example, * . Only m/\*/ will do which I can't use because of false positives. Is there any workaround? from the comments - false positives are: ** , example* , exam*ple what the regex is intended for? - It should extract

Bash regex ungreedy match

和自甴很熟 提交于 2021-02-04 22:16:15
问题 I have a regex pattern that is supposed to match at multiple places in a string. I want to get all the match groups into one array and then print every element. So, I've been trying this: #!/bin/bash f=$'\n\tShare1 Disk\n\tShare2 Disk\n\tPrnt1 Printer' regex=$'\n\t(.+?)\\s+Disk' if [[ $f =~ $regex ]] then for match in "${BASH_REMATCH[@]}" do echo "New match: $match" done else echo "No matches" fi Result: New match: Share1 Disk Share2 Disk New match: Share1 Disk Share2 The expected result

replacing a placeholder in a html file with 1-n specific values defined in a config.json using shellscript [closed]

Deadly 提交于 2021-02-04 21:59:08
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago . Improve this question The Problem: I need to replace a placeholder ( __PLACEHOLDER__ ) in a html file index.html with 1-n specific values defined in a config.json file. what I tried: replacing the placeholder inside index.html with new content: echo "${html//__PLACEHOLDER__/$replace}" > index.html

replacing a placeholder in a html file with 1-n specific values defined in a config.json using shellscript [closed]

浪子不回头ぞ 提交于 2021-02-04 21:58:23
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago . Improve this question The Problem: I need to replace a placeholder ( __PLACEHOLDER__ ) in a html file index.html with 1-n specific values defined in a config.json file. what I tried: replacing the placeholder inside index.html with new content: echo "${html//__PLACEHOLDER__/$replace}" > index.html

Phone number validation with plus sign optional

别说谁变了你拦得住时间么 提交于 2021-02-04 21:56:13
问题 How can i validate a phone number with plus sign optional only at the beginning and after that any number of digits with number only. I tried this:- /^\+(?:[\d]*)$/ How will be the modification 回答1: /^\+?(?:[\d]*)$/ The questionmark tells that the plus sign can be there or not. However, your expression can be optimized quite a bit: /^\+?\d+$/ I changed the * to a + as the expression would match just a plus sign. \d* suggests that it should match 0 or more digits. Here's a demo on Regexr. 来源: