I have the following groovy instructions applied on Jenkins.
stage('Replace content') {
steps {
contentReplace(
configs: [
fileContentReplaceConfig(
configs: [
fileContentReplaceItemConfig(
search: ".appName.*",
replace: ''
)
],
fileEncoding: 'UTF-8',
filePath: 'register.scala')
])
}
}
What is the meaning of the pattern ".appName.*"? Every line which contains the word 'appName', the entire line will be removed in register.scala file?
Content Replace plugin
The Content Replace plugin site states the following
Regex expression for search. e.g. (Version=)([0-9]+.[0-9]+.[0-9]+)
It is a regular expression. It's not necessarily the entire line. Here is an example string: asdfasdfappNameasdf this would be replaced with asdfasd. So it will replace appName, a character before appName, and everything after appName
Below is a pattern matching example from regexr
Related
So i'm creating a 'lua' tokenizer using Monarch and Monaco editor, I have the basic variables and stuff setup, but the only problem is I have no idea how to add a multi-line string.
I see they did it with their own monaco but that is using the same character which is `
however for lua to create a multi-line string you need to use [[ and close it with ]]
Image of javascript multiline in their example.
https://i.imgur.com/iZufBn9.png
This is (from my understanding) the tokens they used in Monarch
// strings
[/`/, 'string', '#string_backtick'],
string_backtick: [
[/\$\{/, { token: 'delimiter.bracket', next: '#bracketCounting' }],
[/[^\\`$]+/, 'string'],
[/#escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/`/, 'string', '#pop']
],
I am looking at a situation where I'd like to bring some structure to what would be a string in an typical language. And wondering how to use Rebol's parts box to do it.
So let's say I've got a line that looks like this in the original language I'm trying to dialect:
something = ("/foo/mumble" "/foo/${BAR}/baz")
I want to use Rebol's primitives, so certainly a file path. Here is a random example of what I thought of off the top of my head:
something: [%/foo/mumble [%/foo/ BAR %/baz]]
If it were code you'd use REJOIN or COMBINE. But this is not designed to be executed, it's more like a configuration file. You're not supposed to be running arbitrary code, just getting a list of files.
I'm not sure about how feasible it is to stick with strings and yet still have these type as FILE!. Not all characters work in a FILE!, for instance:
>> load "%/foo/${BAR}/baz"
== [%/foo/$ "BAR" /baz]
It makes me wonder what my options are in Rebol data that's supposed to represent a configuration file. I can use plain old strings and do substitutions like other things do. Maybe REWORD with an OBJECT block to represent the environment?
What is the 'reword' function in Rebol and how do I use it?
In any case, I want to know how to represent a filename in a declarative context with environment variable substitutions like this.
I should use file! Your example need "" after %
f: load {%"/foo/${BAR}/baz"}
replace f "${BAR}" "MYVALUE" ;== %/foo/MYVALUE/baz
you could use path! with parens.
the only issue is the root, for which you can use another character to replace the "%" used for files... let's use '! (note this should be a word 'valid character).
when calling to-block on a path! type, it returns each part as its own token... useful.
to-block '!/path/(foo)/file.txt
== [! path (foo) file.txt]
here is a little script which loads three paths and uses parens as a constructed part of the path and uses tags to escape path-illegal characters (like a space!)
environments: make object! [
foo: "FU"
bar: "BR"
]
paths: [
!/path/(foo)/file.txt
!/root/<escape weird chars $>/(bar ".txt")
!/("__" foo)/path/(bar)
]
parse paths [
some [
(print "------" )
set data path! here: ( insert/only here to-block data to-block data )
(out-path: copy %"" )
into [
path-parts: (?? path-parts)
'!
some [
[ set data [word! | tag! | number!] (
append out-path rejoin ["/" to-string data]
)]
|
into [
( append out-path "/")
some [
set data word! ( append out-path rejoin [to-string get in environments data] )
| set data skip ( append out-path rejoin [ to-string data])
]
]
| here: set data skip (to-error rejoin ["invalid path token (" type? data ") here: " mold here])
]
]
(?? out-path)
]
]
Note this works both in Rebol3 and Rebol2
output is as follows:
------
path-parts: [! path (foo) file.txt]
out-path: %/path/FU/file.txt
------
path-parts: [! root <escape weird chars $> (bar ".txt")]
out-path: %/root/escape%20weird%20chars%20$/BR.txt
------
path-parts: [! ("__" foo) path (bar)]
out-path: %/__FU/path/BR
------
I have a ruby array like below
tomcats = [
'sandbox',
'sandbox_acserver',
'sandbox_vgw'
]
I need to pass the string as a hash index like below
tomcats.each do |tomcat_name|
obi_tomcat '#{tomcat_name}' do
Chef::Log::info("Creating tomcat instance - #{tomcat_name}")
Chef::Log::info("#{node['obi']['tomcat']['sandbox'][:name]}") // works
Chef::Log::info("#{node['obi']['tomcat']['#{tomcat_name}'][:name]}") // doesn't work
end
end
The last log throws an error since the access with #{tomcat_name} is nil. I'm new to ruby. How do I access with key as the tomcat_name ?
In normal code, you'd write:
node['obi']['tomcat'][tomcat_name][:name]
In a string interpolation (useless here, because it's the only thing in the string in this case), it is completely the same:
"#{node['obi']['tomcat'][tomcat_name][:name]}"
#{} only works in double quote, as "#{tomcat_name}".
But you don't need the syntax here, just use [tomcat_name] directly.
When I saw this question, I'm thinking whether ruby placeholder could be put inside other placeholder in string interpolation. And I found that ruby actually support it, and most interesting thing is that you don't need to escape the " inside the string.
Although it is not very useful in this case, it still works if you write as below:
Chef::Log::info("#{node['obi']['tomcat']["#{tomcat_name}"][:name]}")
Below is an simple example of placeholder inside other placeholder:
tomcats = [
'sandbox',
'sandbox_acserver',
'sandbox_vgw'
]
node = {
'sandbox_name' => "sandbox name",
'sandbox_acserver_name' => "sandbox_acserver name",
'sandbox_vgw_name' => "sandbox_vgw name",
}
tomcats.each do | tomcat |
puts "This is tomcat : #{node["#{tomcat}_name"]}"
end
I am using this plugin:
compile ":html-cleaner:0.2"
I want to keep \n characters in my strings
def s = "a\nb\nc\n"
println s
Prints:
a
b
c
When I use:
println cleanHtml(s, 'none')
It prints:
a b c
You can create a whitelist using:
htmlcleaner {
whitelists = {
whitelist("sample") {
startwith "none"
allow "b", "p", "i", "span"
}
}
}
How can I keep the \n characters from being stripped?
Disclaimer: I'm not all that familiar with Jsoup or the html-cleaner plugin.
However, I can read the source and documentation for both and it would appear this is not possible with the plugin. Looking at the plugin source code for HtmlCleaner you will see the following relevant line:
return Jsoup.clean(unsafe, whitelists[whitelist])
This is relevant because in order to preserve new line characters in Jsoup you need to set printPretty(false) on the output settings, which is true by default. This SO question & answer outlines this.
It would appear that you will need to use Jsoup directly instead of using the plugin. Alternatively you could fork and patch the plugin to allow this to be configured.
I'm implementing a search in my website, and would like to support searching for exact phrases. I want to end up with an array of terms to search for; here are some examples:
"foobar \"your mom\" bar foo" => ["foobar", "your mom", "bar", "foo"]
"ruby rails'test course''test lesson'asdf" => ["ruby", "rails", "test course", "test lesson", "asdf"]
Notice that there doesn't necessarily have to be a space before or after the quotes.
I'm not well versed in regular expressions, and it seems unnecessary to try to split it repeatedly on single characters. Can anybody help me out? Thanks.'
You want to use this regular expression (see on rubular.com):
/"[^"]*"|'[^']*'|[^"'\s]+/
This regex matches the tokens instead of the delimiters, so you'd want to use scan instead of split.
The […] construct is called a character class. [^"] is "anything but the double quote".
There are essentially 3 alternates:
"[^"]*" - double quoted token (may include spaces and single quotes)
'[^']*' - single quoted token (may include spaces and double quotes)
[^"'\s]+ - a token consisting of one or more of anything but quotes and whitespaces
References
regular-expressions.info/Character Class
Snippet
Here's a Ruby implementation:
s = %_foobar "your mom"bar'test course''test lesson'asdf_
puts s
puts s.scan(/"[^"]*"|'[^']*'|[^"'\s]+/)
The above prints (as seen on ideone.com):
foobar "your mom"bar'test course''test lesson'asdf
foobar
"your mom"
bar
'test course'
'test lesson'
asdf
See also
Which style of Ruby string quoting do you favour?