How to CAPITALIZE many character in string with iMacros Eval - eval

How to replace many character with their CAPITALIZED form in a string/array in iMacros ( a to A , b to B etc)
hopely i can get my problem with imacros.. i just wanna do :
tag 1 is abcd, and i want replace it with ABCD (capital).
for replace many character to one character usualy i use this code
" SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/[():;?!': '' ']/g, '-');") "
its mean replace char / [ \ ( \ ) : ; ? ! to " - "
but how to replace per character like a to A, b to B (capital)
thanks for your attention..

I'm barely starting to use iMacros, but i found your question looking to answer one of my own, and shortly afterwards I found this in the wiki:
Manipulate extraction
Transform extraction to uppercase characters:
VERSION BUILD=7400919 RECORDER=FX
TAB T=1
URL GOTO=http://android-developers.blogspot.com/2011/09/preparing-for-handsets.html
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=P ATTR=TXT:Early<SP>this<SP>year,* EXTRACT=TXT
SET !VAR1 EVAL("var s=\"{{!EXTRACT}}\"; s.toUpperCase()")
PROMPT {{!VAR1}}
This is the page:
http://wiki.imacros.net/EVAL
Hope it helps.

If someone will need to capitalize only first letter of each word (for me it looks not possible to do with just regex \U$1):
SET !EXTRACT EVAL("var s=\"{{!EXTRACT}}\"; s.replace(/(^\w|\s\w)/g, m => m.toUpperCase());")

Related

Regex for Masking Data in a JSON Array

I've got a requirement to mask the incoming JSON request inside an array using regular expression on Splunk indexer. The JSON data looks like this:
{"Name":["Jobs","Bill"]}
I'm expected to mask the incoming data so that it looks like this:
{"Name":["******","******"]}
And the regex I'm using to mask the data looks something like this:
s/\"Name\":\"[^"]*\"/"Name":"******"/g
But for some reason I'm unable to mask the JSON data. Could any of you good folks please help?
You can use
s/(?:\G(?!^)\",|\"Name\":\[)\"\K[^\"]*/******/g
To support escaped \", use
s/(?:\G(?!^)\",|\"Name\":\[)\"\K[^\"\\]*(?:\\.[^\"\\]*)*/******/g
See the regex demo #1 and regex demo #2
Details
(?:\G(?!^)\",|\"Name\":\[) - either the end of the previous match and then ", substring, or "Name":[ substring
\" - " char
\K - match reset operator discarding all text matched so far
[^\"]* - any zero or more chars other than ".
[^\"\\]*(?:\\.[^\"\\]*)* - any 0+ chars other than " and \ and then zero or more repetitions of a \ followed with any char but a line break char and then any 0+ chars other than \ and ".

Hi! How i can write symbol & to variable in CMD ? )

I need to write symbol & to variable in CMD for word is like = adc&def.
There are two ways to do that:
Use a caret ^ to escape the character. It will work for these characters: & < > ^ | (You escape a caret by using a caret).
Use double-quotes. By using double quotes it's not necessary to escape characters (except exclamation marks when using EnableDelayedExpansion.
So, the final solution could be:
set "var=abc&def"
or set var=abc^&def.

Python joining a list by "\"

Lets say I have a list of elements.
l = ["xf3", "x03", "x8c"] etc.
Now I would like to join the elements inside my list with a "\". I tried r"\".join(l) but it didn't work.
\ is used to escape 'special' characters, hence a Python string can not terminate with a single \ because it escapes the closing quote.
You have to escape it by using a second \, ie '\\'.join(l)
l = ["xf3", "x03", "x8c"]
'\\'.join(l)
The important part is to escape the '\\' as inn Python Strings:
the backslash "\" is a special character, also called the "escape"
character. It is used in representing certain whitespace characters:
"\t" is a tab, "\n" is a newline, and "\r" is a carriage return. As well "\"
can be used to escape itself: "\" is the literal backslash character.
I'm assuming is what you actually want is to create a string containing those escaped characters. The easiest way I can think of is ast.literal_eval:
>>> import ast
>>> ast.literal_eval("'\\" + "\\".join(l) + "'")
'รณ\x03\x8c'
This works by first creating a string of those strings joined by backslash characters (xf3\x03\x8c), surrounding those by quotes and adding the initial backslash ('\xf3\x03\x8c'), and finally, by evaluating it as a literal, to turn it from a length 12 string into a length 3 string.

SQL Select statement until a character

I'm looking to extract all the text up until a '\' (backslash).
The substring is required to remove all proceeding characters (17 in total) and so I would like to return all after the 17th until it comes across a backslash.
I've tried using charindex but it doesn't seem to stop at the \ it returns characters afterward. My code is as follows
SELECT path, substring(path,17, CHARINDEX('\',Path)+ LEN(Path)) As Data
FROM [Table].[dbo].[Projects]
WHERE Path like '\ENQ%\' AND
Deleted = '0'
Example
The below screen shot shows the basic query and result i.e the whole string
I then use substring to remove the first X characters as there will always be the same amount of proceeding characters
But what Im actually after is (based on the above result) the "Testing 1" "Testing 2" and "Testing ABC" section
The substring is required to remove all proceeding characters (17 in total) and so I would like to return all after the 17th until it comes across a backslash.
select
substring(path,17,CHARINDEX('\',Path)-17)
from
table
To overcome Invalid length parameter passed to the LEFT or SUBSTRING function error, you can use CASE
select
substring(path,17,
CASE when CHARINDEX('\',Path,17)>0
Then CHARINDEX('\',Path)-17)
else VA end
)
from
table

How do I set word delimiters?

User's guide chapter 6.1.5 The Word Chunk A word is a string of characters delimited by space, tab, or return characters or enclosed by double quotes. Is it possible to have additional word delimiters?
I have the following code snippet taken from the User's Guide chapter 6.5.1 'When to use arrays', p. 184
on mouseUp
--cycle through each word adding each instance to an array
repeat for each word tWord in field "sample text"
add 1 to tWordCount[tWord]
end repeat
-- combine the array into text
combine tWordCount using return and comma
answer tWordCount
end mouseUp
It counts the number of occurences of each word form in the field "Sample text".
I realize that full stops after words are counted as part of the word with the default setting.
How do I change the settings that a full stop (and, or a comma) is considered a word boundary?
Alternatively you could simply remove the offending characters before processing.
This can be done using either the REPLACE function or the "REPLACETEXT function.
The REPLACETEXT function can use a regular expression matchstring but is slower than the REPLACE function. So here I am using the REPLACE function.
on mouseUp
put field "sample" into twords
--remove all trailing puncuation and quotes
replace "." with "" in twords
replace "," with "" in twords
replace "?" with "" in twords
replace ";" with "" in twords
replace ":" with "" in twords
replace quote with "" in twords
--hyphenated words need to be seperated?
replace "-" with " " in twords
repeat for each word tword in twords
add 1 to twordcount[tword]
end repeat
combine twordcount using return and comma
answer twordcount
end mouseUp
I think you are asking a question about delimiters. Some delimiters are built-in:
spaces for words,
commas for items,
return (CR) for lines.
The ability to create your own custom delimiter property (the itemDelimiter) is a powerful feature of the language, and pertains to "items". You can set this to any single character:
set the itemDelimiter to "C"
answer the number of items in "XXCXXCXX" --call this string "theText"
The result will be "3"
As others have pointed out, the method of replacing one string for another allows formidable control over custom parsing of text:
replace "C" with space in theText
yields "XX XX XX"
Craig Newman
As the User's guide says in chapter 6.1.5 The Word Chunk A word is a string of characters delimited by space, tab, or return characters or enclosed by double quotes.
There is itemDelimiter but not wordDelimiter.
So punctuation as to be removed first before adding the word to the word count array.
This may be done with a function effectiveWord.
function effectiveWord aWord
put last char of aWord into it
if it is "." then delete last char of aWord
if it is "," then delete last char of aWord
if it is ":" then delete last char of aWord
if it is ";" then delete last char of aWord
return aWord
end effectiveWord
on mouseUp
--cycle through each word adding each instance to an array
repeat for each word tWord in field "Sample text"
add 1 to tWordCount[effectiveWord(tWord)]
end repeat
-- combine the array into text
combine tWordCount using return and comma
answer tWordCount
end mouseUp

Resources