regex

awk - Variable expansion in regex

北城以北 提交于 2021-02-04 19:39:19
问题 Why doesn't something like this work: echo 4 | awk --assign=abc=4 '/$abc/' The actual example is much more complicated. Basically I have a regex I need repeated several times so I'm storing it in abc . Is there any way to expand an awk variable in /<regex>/ ? I've tried single and double quotes, every combination. I really need that line to be single quoted because I have several double quotes, it actually looks more like awk --assign=test=something '/$test/ { a lot of stuff here inc $test

Kafka multiple topic consume

女生的网名这么多〃 提交于 2021-02-04 19:31:26
问题 consumer.subscribe(Pattern.compile(".*"),new ConsumerRebalanceListener() { @Override public void onPartitionsRevoked(Collection<TopicPartition> clctn) { } @Override public void onPartitionsAssigned(Collection<TopicPartition> clctn) { } }); How to consume all topics with regex in apache/kafka? I tried above code, but it didn't work. 回答1: For regex use the following signature KafkaConsumer.subscribe(Pattern pattern, ConsumerRebalanceListener listener) E.g. the following code snippet enables the

How to find the whole word in kotlin using regex

余生长醉 提交于 2021-02-04 19:24:07
问题 I want to find the whole word in string. But I don't know how to find the all word in kotlin. My finding word is [non alpha]cba[non alpha]. My example code is bellows. val testLink3 = """cba@cba cba""" val word = "cba" val matcher = "\\b[^a-zA-Z]*(?i)$word[^a-zA-Z]*\\b".toRegex() val ret = matcher.find(testLink3)?.groupValues But output of my source code is "cba" My expected value is string array such as "{cba, cba, cba}". How to find this value in kotlin language. 回答1: You may use val

How to substitute words in Git history & properly debug related problems?

£可爱£侵袭症+ 提交于 2021-02-04 19:24:05
问题 I'm trying to remove sensitive data like passwords from my Git history. Instead of deleting whole files I just want to substitute the passwords with removedSensitiveInfo . This is what I came up with after browsing through numerous StackOverflow topics and other sites. git filter-branch --tree-filter "find . -type f -exec sed -Ei '' -e 's/(aSecretPassword1|aSecretPassword2|aSecretPassword3)/removedSensitiveInfo/g' {} \;" When I run this command it seems to be rewriting the history (it shows

Regex: How not to replace specific word in any html tag?

旧城冷巷雨未停 提交于 2021-02-04 19:20:45
问题 So let's assume I have a text like this: This is a great test! We're testing something awesome. Click here to <a href="whatever">test it!</a>. I want to add some color to the word "test", but not if it's in an a tag. I've tried doing this: /(?<!href="(.*?)">)test/ But it doesn't work. It works like this: /(?<!href="whatever">)test/ But of course I have many links, so this isn't an option. The whole code would be something like this: $replacement = preg_replace('/(?<!href="SOLUTION HERE">)test

Regex: How not to replace specific word in any html tag?

大兔子大兔子 提交于 2021-02-04 19:19:05
问题 So let's assume I have a text like this: This is a great test! We're testing something awesome. Click here to <a href="whatever">test it!</a>. I want to add some color to the word "test", but not if it's in an a tag. I've tried doing this: /(?<!href="(.*?)">)test/ But it doesn't work. It works like this: /(?<!href="whatever">)test/ But of course I have many links, so this isn't an option. The whole code would be something like this: $replacement = preg_replace('/(?<!href="SOLUTION HERE">)test

Regex for multiple words separated by spaces or commas

孤者浪人 提交于 2021-02-04 19:18:05
问题 I'm trying to create regex for multiple strings separated by comma or space. Lorem Ipsum // valid Lorem, Ipsum //valid Lorem, Ipsum, Ipsum, Ipsum // multiple valid Lorem // invalid without space/comma Here is what i have so far: ^\w+(,\s*\w+){3}$/ 回答1: You may use ^\w+(?:(?:,\s\w+)+|(?:\s\w+)+)$ See the regex demo. The regex matches: ^ - start of string \w+ - 1+ word chars (?: - start of an alternation group: (?:,\s\w+)+ - , , whitespace, 1+ word chars | - or (?:\s\w+)+ - whitespace and then

Extract string from text file via Powershell

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-04 18:51:28
问题 I have been trying to extract certain values from multiple lines inside a .txt file with PowerShell. Host Class INCLUDE vmware:/?filter=Displayname Equal "server01" OR Displayname Equal "server02" OR Displayname Equal "server03 test" This is what I want : server01 server02 server03 test I have code so far : $Regex = [Regex]::new("(?<=Equal)(.*)(?=OR") $Match = $Regex.Match($String) 回答1: You may use [regex]::matches($String, '(?<=Equal\s*")[^"]+') See the regex demo. See more ways to extract

Regex for URL with query string

萝らか妹 提交于 2021-02-04 18:51:27
问题 I'm trying to create a regular expression to use as a rule in fiddler. I'm not very good at regular expressions. This regular expression: http://myServer:28020/MyService/ItemWebService.json?([a-zA-Z]+) Matches the URL below: http://myServer:28020/MyService/ItemWebService.json?action=keywordSearch&username=StockOnHandPortlet&sessionId=2H7Rr9kCWPgIZfrxQiDHKp0&keywords=blue&itemStatus=A So far so good. But why when I try this regular expression: http://myServer:28020/MyService/ItemWebService

Regex for URL with query string

社会主义新天地 提交于 2021-02-04 18:50:45
问题 I'm trying to create a regular expression to use as a rule in fiddler. I'm not very good at regular expressions. This regular expression: http://myServer:28020/MyService/ItemWebService.json?([a-zA-Z]+) Matches the URL below: http://myServer:28020/MyService/ItemWebService.json?action=keywordSearch&username=StockOnHandPortlet&sessionId=2H7Rr9kCWPgIZfrxQiDHKp0&keywords=blue&itemStatus=A So far so good. But why when I try this regular expression: http://myServer:28020/MyService/ItemWebService