I'm trying to replace the hardcode in the Helm3 template with variables.
the name of the variable must match the value of the string name from the Values.yaml file. (name: test-rrrr-blabla-file) without spaces and only the last 2 blocks, i.e. blablafile.
Adequate examples in the
https://helm.sh/docs/chart_best_practices/templates/
I didn't find how to do it, tried the following expression:
{{- default .Chart.Name .Values | (split “-” .Values.nameOverride)._3 }}-{{ (split “-” .Values.nameOverride)._4 }}
but it didn't work.
Also found undocumented capabilities here:
https://github.com/Masterminds/sprig/blob/master/docs/strings.md#regexfind
Not sure exactly, maybe need to use or regexSplit
or regex_replace, but I don't understand how to properly compose the expression... maybe you have come across this in practice?
Any help would be appreciated.
Thank you!
Related
I am trying to use the tags filter for a job in CircleCI.
workflows:
foo:
jobs:
- bar:
filters:
tags:
only: /\d+/
The only key of tags is what I am interested in. Here's a sample regex: /\d+/
It's designed to match 1+ digits
Currently it doesn't match numbers with 2+ digits, because I need to add the global flag, /g
See this question for why
The correct regex would be /\d+/g
The CircleCI docs point to java.util.regex docs
Which didn't help me figure out if CircleCI regex would support flags :S
My question(s)
Does CircleCI regex support the use of flags?
How can I use flags in a regex?
Can you provide a link to an example?
Will my above regex of /\d+/g work?
I don't think CircleCI supports the use of flags, it doesn't seem necessary.
Looking at the example on https://circleci.com/docs/2.0/workflows/#using-regular-expressions-to-filter-tags-and-branches
You should ensure that you use ^ and $ to encapsulate your match pattern otherwise they will early out.
e.g. /\d+/ will match "123" but will stop as soon as the first digit is encountered, however /^\d+$/ will not since the pattern has start/end markers.
I'm new to GREP in BBEdit. I need to find a string inside an XML file. Such string is enclosed in quotes. I need to replace only what's inside the quotes.
The problem is that the replacement string starts with a number thus confuses BBEdit when I put together the replacement pattern. Example:
Original string in XML looks like this:
What I need to replace it with:
01 new file name.png
My grep search and replace patterns:
Using the replacement pattern above, BBEdit wrongly thinks that the first backreference is "\101" when what I really need it understand is that I mean "\01".
TIA for any help.
Your example is highly artificial because in fact there is no need for your \1 or \3 as you know their value: it is " and you can just type that directly to get the desired result.
"01 new file name.png"
However, just for the sake of completeness, the answer to your actual question (how to write a replacement group number followed by a number) is that you write this:
\0101 new file name.png\3
The reason that works is that there can only be 99 capture groups, so \0101 is parsed as \01 (the first capture group) followed by literal 01.
I'm trying to replace the html entity for a blank space with an actual space between occurrences of {{ and }}
Example example
"this is a gap {{ for user in users }}" =>
"this is a gap {{ for user in users }}"
I've found answers similar which had led me to write something like this (which doesn't work)
.gsub(/(?<=\{\{).*( ?).*(?=\}\})/,' ')
Any help with such a regex would be appreciated thanks!
You can do this with a complex regular expression I agree, but I find it simpler to use nested substitution. First use gsub to find the bracketed substrings and then use another to replace the entity.
string = 'this is a gap {{ for user in users }}'
result = string.gsub(/{{.*?}}/){ |s| s.gsub(/ /, ' ') }
# => "this is a gap {{ for user in users }}"
Single call to gsub using \K and \G
It's a bit tricky, but in Ruby 2.0+, we can do it with a compact regex thanks to the \K and \G tokens. Use this regex and replace with a space:
[^{}]*\K(?:{{|\G).*?\K (?=[^{]*})
See demo.
In Ruby:
result = subject.gsub(/[^{}]*\K(?:{{|\G).*?\K (?=[^{]*})/, ' ')
Explanation
[^{}]* matches any chars that are not braces
\K tells the engine to drop what was just matched
(?:{{|\G) either matches the opening curlies or asserts that we are positioned after the last match
.*?\K lazily matches chars (and drops them), up to...
Our match!
which, as the lookakead (?=[^{]*}) asserts, must be followed by any chars that are not an opening brace before meeting a closing brace
Here is my sample string.
[echo] The SampleProject solution currently has 85% code coverage.
My desired output should be.
The SampleProject solution currently has 85% code coverage.
Btw, I had this out because I'm getting through the logs in my CI using Jenkins.
Any help? Thanks..
You can try substText parameter in BUILD_LOG_REGEX token to substitute the text matching your regex
New optional arg: ${BUILD_LOG_REGEX, regex, linesBefore, linesAfter, maxMatches, showTruncatedLines, substText} which allows substituting text for the matched regex. This is particularly useful when the text contains references to capture groups (i.e. $1, $2, etc.)
Using below will remove prefix [echo] from all of your logs ,
${BUILD_LOG_REGEX, regex="^\[echo] (.*)$", maxMatches=0, showTruncatedLines=false, substText="$1"}
\[[^\]]*\] will match the bit you want to remove. Just use a string replace function to replace that bit with an empty string.
Andrew has the right idea, but with Perl-style regex syntaxes (which includes Java's built-in regex engine), you can do even better:
str.replaceAll("\\[.*?\\]", "");
(i.e., use the matching expression \[.*?\]. The ? specifies minimal match: so it will finish matching upon the first ] found.)
vi treats dash - and space as word separators for commands such as dw and cw.
Is there a way to add underscore _ as well?
I quite often want to change part of a variable name containing underscores, such as changing src_branch to dest_branch. I end up counting characters and using s (like 3sdest), but it would be much easier to use cw (like cwdest).
Is there a way to add underscore _ as well?
:set iskeyword-=_
What is, and is not a member character to keywords depends on the language. For help on iskeyword use :help iskeyword.
In case you're using vim, you can change that by setting the iskeyword option (:he iskeyword). If that is not an option, you can always use ct_ instead of counting.
One other good option in such cases is to use camelcasemotion plugin.
It adds new motions ,b, ,e, and ,w, which work analogously with b, e, and w, except that they recognize CamelCase and snake_case words. With it you can use
c,edest
and this will replace "src_branch" with "dest_branch" if your cursor was on first character of "src_branch".
You could type cf_dest_ and save the counting part.
Edit: or as suggested: ct_ changes text until right before the underline character. (I'm using the f motion more, so it came more naturally to me)
Or you could redefine 'iskeyword' (:help iskeyword for details).
I was just looking at this myself and added this to my .vimrc:
set iskeyword=!-~,^*,^45,^124,^34,192-255,^_
My .vimrc had issues with ^| and ^", which was part of the default iskeyword for my setup, so I changed to their ascii values and it works fine. My main modification was to add "^_" to the end of the default setting to keep vim from seeing underscore as being part of a word.
To delete to the next underscore enter "df_"
To change to the next underscore enter "cf_"
NOTE: don't include the double quotes.