Created a JMeter regular expression and getting 4 matches, i need only value "441157" and I'm unable to get it.
Jmeter RegEx- "TimeSeriesId":(\b[0-9]+\b)`enter code here`
Match count: 4
Match[1][0]="TimeSeriesId":441157`enter code here`
Match[1][1]=441157`enter code here`
Match[2][0]="TimeSeriesId":441157`enter code here`
Match[2][1]=441157`enter code here`
Match[3][0]="TimeSeriesId":441157`enter code here`
Match[3][1]=441157`enter code here`
Match[4][0]="TimeSeriesId":441157`enter code here`
Match[4][1]=441157`enter code here`
Try amending your regular expression to look like:
"TimeSeriesId":(\d+)`enter code here`
It should give you one match only:
References:
JMeter: Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter
Perl5 Regular Expression Syntax
Related
I am trying to replace a date format in all lines of text file using NiFi. The file looks like this:
ABCDE,20200619,23.8
FGHIJ,20200619,14.5
...
I am trying to do this using ReplaceText processor to change 20200619 to 2020-06-19. I've made regex expression matching the date ((20\d{6},)) and I have checked that it's working: when i write $1 TESTING, in Replacement value it works as expected (single line of file looks like ABCDE,20200619, TESTING,23.8).
The problem is when I try to use Expression Language and :substring function. This is my code in Replacement value:
${$1:substring(0, 4)}-${$1:substring(4, 6)}-${$1:substring(6, 8)}
But I get following error:
NiFi Error
It looks like the Expression Language can't access my $1 variable. How can I access my Regex Capturing Group variable inside Expression Language?
This is my processor:
NiFi Processor
I found the answer: when trying to access Regex Capturing Group inside ${...} we need to use it with apostrophes, so the code like this works:
${'$1':substring(0, 4)}-${'$1':substring(4, 6)}-${'$1':substring(6, 8)}
I'm reading through the jison documentation and one of the examples gives a lexer rule that matches the end of file (<<EOF>>). However, that can only be used if you are writing the grammar in JISON format. Instead, I am using the JSON format to describe my grammar, but I cannot find anything in the documentation describing how to match the end of file. I have tried using "<<EOF>>" as the lexer rule, but that literally matches the string <<EOF>>.
How do I do this? Is there more documentation for jison somewhere that I'm missing?
After digging into the source code for lex-parser, it looks like $ does what I want. Instead of matching the end of a line, it matches the end of a file. <<EOF>> actually gets converted to $ when parsing the lex section of a jison file.
The following code give two errors which I am not able to resolve. Any help would be appreciated:
random.rb:10: can't find string "TEMPLATE" anywhere before EOF
random.rb:3: syntax error, unexpected end-of-input
Code:
id = 2
File.open("#{id}.json","w") do |file|
file.write <<TEMPLATE
{
"submitter":"#{hash["submitter"]}",
"quote":"#{hash["quote"]}",
"attribution":"#{hash["attribution"]}"
}
TEMPLATE
end
From the documentation (emphasis mine):
The heredoc starts on the line following <<HEREDOC and ends with the next line that starts with HEREDOC
Your code doesn't contain a line starting with TEMPLATE. If your text editor (or IDE) supports regular expressions in searches, try ^TEMPLATE.
You can either remove the spaces or if you want to keep them, change <<TEMPLATE into <<-TEMPLATE. The addition of - instructs the Ruby parser to search for an (possibly) intended TEMPLATE like you have in your code.
I'm trying to convert this ruby regex to go.
GROUP_CALL = /^(?<i1>[ \t]*)group\(?[ \t]*(?<grps>#{SYMBOLS})[ \t]*\)?[ \t]+do[ \t]*?\n(?<blk>.*?)\n^\k<i1>end[ \t]*$/m
I converted it to
groupCall := regexp.MustCompile("^(?P<i1>[ \\t]*)group\\(?[ \\t]*(?P<grps>(?::\\w+|:\"[^\"#]+\"|:'[^']+')([ \\t]*,[ \\t]*(?::\\w+|:\"[^\"#]+\"|:'[^']+'))*)[ \\t]*\\)?[ \\t]+do[ \\t]*?\\n(?P<blk>.*?)\\n^\\k<i1>end[ \\t]*$/s")
but when run I get this error
error parsing regexp: invalid escape sequence: \k
There's no mention of \k in the go docs, is there no equivalent in go?
lookbehinds aren't supported neither are backreferences like #stribizhev mentioned.
Regular Expression 2 (RE2) Syntax Reference:
https://github.com/google/re2/wiki/Syntax
The syntax of the regular expressions accepted is the same general
syntax used by Perl, Python, and other languages. More precisely, it
is the syntax accepted by RE2 and described at
//code.google.com/p/re2/wiki/Syntax, except for \C. --GoLang Docs
(ref: https://golang.org/pkg/regexp/)
Is it possible to do a string substitution/transformation in Puppet using a regular expression?
If $hostname is "web1", I want $hostname_without_number to be "web". The following isn't valid Puppet syntax, but I think I need something like this:
$hostname_without_number = $hostname.gsub(/\d+$/, '')
Yes, it is possible.
Check the puppet function reference: http://docs.puppetlabs.com/references/2.7.3/function.html
There's a regular expression substitution function built in. It probably calls the same underlying gsub function.
$hostname_without_number = regsubst($hostname, '\d+$', '')
Or if you prefer to actually call out to Ruby, you can use an inline ERB template:
$hostname_without_number = inline_template('<%= hostname.gsub(/\d+$/, "") %>')
In this page:
https://blog.kumina.nl/2010/03/puppet-tipstricks-testing-your-regsubst-replacings-2/comment-page-1/
it is quite well explained and there is a fantastic trick for testing your regular expressions with irb.
Whith this link and the answer of freiheit I could resolve my problem with substitution of '\' for '/'.
$programfiles_sinbackslash = regsubst($env_programfiles,'\','/','G')