Insert a character in a string at a certain position iMacros - imacros

I'm getting in an int with unknown number of digits, I want to add a "." decimal point 2 digits from the end.
example:
TAG POS=1 TYPE=div ATTR=CLASS:price EXTRACT=TXTALL 'the price text are 48852
SET !VAR1 {{!EXTRACT}}
'processing...
PROMPT {{!VAR1}} 'print 488.52

Try this way:
TAG POS=1 TYPE=div ATTR=CLASS:price EXTRACT=TXTALL
SET !VAR1 EVAL("var n = '{{!EXTRACT}}'.trim(); n.substr(0, n.length - 2) + '.' + n.slice(-2);")
' print 488.52 '
PROMPT {{!VAR1}}

Related

Regex to match variables only when inside quotes

I have many sql files. I am trying to locate files that contain a variable (format of #varname) ONLY if they appear within matching single or double quotes. I only care that it exists and is there, I just need to know the files that this occurs in.
I can match all the quoted strings, but can't figure out how to test that even just a single # char appears within the match
matching single and double quote pairs (["'])(.*?)\1
example file:
...sql statements
select #sql = 'select * from
Users where id = #id '
...more sql statements
Thanks in advance.
EDIT
Here is a better example file, with comments (sql comments) on which statements should match and examples of ones that shouldn't
...sql statements
-- only this quoted string would match
select #sql = "select * from
Users where id = #id "
-- other statements that wouldn't match because not in a pair of quotes
if ltrim(isnull(#stat,'')) <> '' and #stat <> '""'
begin
select #sql = #sql + " and Stat in ("+#stat+")"
end
if isnull(#atype,'') <> ''
begin
select #sql = #sql + " and Type in ("+#atype+")"
end
...more sql statements
For the sample text given....
Try:
(?:\s|=)(?:\"[^"]*#[^"]*\"|(?:\s|=)\'[^']*#[^']*\')
Demo:
https://regex101.com/r/BXcYt4/1
Using PCRE and to
to test that even just a single # char appears within the match
You can use an alternation excluding either " or ' and also exclude matching an # adding it to the negated character class.
To get both values in the same group, you can use a branch reset group.
=\h*(?|"([^"#]*#[^"#]+)"|'([^#']*#[^'#]*)')
The pattern matches:
=\h* Match = and optional horizontal whitespace chars
(?| Branch reset group
"( Match " and start group 1
[^"#]*# Match optional chars other than " or # and then match #
[^"#]+ Match 1+ chars other than " or #
)" Close group 1 and atch "
| Or
'([^#']*#[^'#]*)' The same as previous pattern, this time for '
) Close branch reset group
Regex demo

extract 1st line with specific pattern using regexp

I have a string
set text {show log
===============================================================================
Event Log
===============================================================================
Description : Default System Log
Log contents [size=500 next event=7 (not wrapped)]
6 2020/05/22 12:36:05.81 UTC CRITICAL: IOM #2001 Base IOM
"IOM:1>some text here routes "
5 2020/05/22 12:36:05.52 UTC CRITICAL: IOM #2001 Base IOM
"IOM:2>some other text routes "
4 2020/05/22 12:36:05.10 UTC MINOR: abc #2001 some text here also 222 def "
3 2020/05/22 12:36:05.09 UTC WARNING: abc #2011 some text here 111 ghj"
1 2020/05/22 12:35:47.60 UTC INDETERMINATE: ghe #2010 a,b, c="7" "
}
I want to extract the 1st line that starts with "IOM:" using regexp in tcl ie
IOM:1>some text here routes
But implementation doesn't work, Can someone help here?
regexp -nocase -lineanchor -- {^\s*(IOM:)\s*\s*(.*?)routes$} $line match tag value
You may use
regexp -nocase -- {(?n)^"IOM:.*} $text match
regexp -nocase -line -- {^"IOM:.*} $text match
See the Tcl demo
Details
(?n) - (same as -line option) newline sensitive mode ON so that . could not match line breaks ( see Tcl regex docs: If newline-sensitive matching is specified, . and bracket expressions using ^ will never match the newline character (so that matches will never cross newlines unless the RE explicitly arranges it) and ^ and $ will match the empty string after and before a newline respectively, in addition to matching at beginning and end of string respectively)
^ - start of a line
"IOM: - "IOM: string
.* - the rest of the line to its end.
In addition to #Wiktor's great answer, you might want to iterate over the matches:
set re {^\s*"(IOM):(.*)routes.*$}
foreach {match tag value} [regexp -all -inline -nocase -line -- $re $text] {
puts [list $tag $value]
}
IOM {1>some text here }
IOM {2>some other text }
I see that you have a non-greedy part in your regex. The Tcl regex engine is a bit weird compared to other languages: the first quantifier in the regex sets the greediness for the whole regex.
set re {^\s*(IOM:)\s*\s*(.*?)routes$} ; # whole regex is greedy
set re {^\s*?(IOM:)\s*\s*(.*?)routes$} ; # whole regex in non-greedy
# .........^^

multiline textbox validation ms access

Hi I am pretty new to Ms Access and I could use some of your expertise to advise:
I would like to validate the text of a multiline textbox, so that the user can only enter 2 capital letters - 7 numbers - semi-colon - new line. As an example, the textbox would look like this (but with each entry on a new line, since I have it so that enter makes a new line in the textbox
AB1234567; SE0001848; SE0019591; RE0010599; etc.
I think this is too complex for a validation rule. I also think it's too complex for an input mask. I started looking into RegEx to validate the text but I am hungup on how to have the code evaluate each new line in the multiline textbox so that the entire textbox is evaluated. Do i need to do a loop of some sort?
Ultimately, I would like the user to get a message box when they enter their text incorrectly that blocks the entry from being added to the record and also explains to the user that they need to modify their entry so that it is valid.
I think your idea of RegEx is the easiest but you'll need to add a reference (see code).
This should do what you want (just replace Text14 with your text control)
Note - I removed the CANCEL=TRUE because that wipes out the users data. The best route woul dbe to make sure the text box is UNBOUND - then if valid you would update the actual field if the RegExp is validated for all lines
Private Sub Text14_BeforeUpdate(Cancel As Integer)
' Requires reference to "Microsoft VBScript Regular Expressions 5.5"
' Under Tools | References
' Add Reference to "Microsoft VBScript Regular Expressions 5.5"
' 2 Capital Letters followed by 7 digits and ";'
Const VALID_LINE As String = "[A-Z]{2}[\d]{7};"
Dim regEx As New RegExp
Dim strData As String ' Read in textbox
Dim varLines As Variant ' Use this to hold lines of text
Dim intNumLines As Integer
Dim intLine As Integer
Dim strLine As String
With regEx
.Global = True
.Multiline = False
.IgnoreCase = False
.Pattern = VALID_LINE
End With
' Replace Text14 with your text box control name
strData = Text14.Value ' Get Data from Text box
' Split data into lines using Carriage Return Line Feed delimiters
varLines = Split(strData, vbCrLf)
' Go thru all lines to check for data issue
intNumLines = UBound(varLines)
For intLine = 0 To intNumLines
strLine = varLines(intLine)
If Not regEx.Test(strLine) Then
MsgBox "Problem with Line #" & (intLine + 1)
' Cancel - if you want to wipe out data
' Cancel = True
Exit Sub
End If
Next
MsgBox "Data Looks Good: All " & intNumLines & " Lines"
End Sub

Java Regex : Replacing multiple words in jsps

I am having Jsp code like -
<input type = "something" name = "something" value = "dto.value" />
Now I want to replace "input" with "form:input", remove name attribute, add new attribute "path" and set "name" attribute value to path such as my final output will be -
<form:input type = "something" path = "dto.value" />
How do I achieve it because I need to do this on over 250 jsps.
If you are using Eclipse IDE, use Ctrl+F to get Find\Replace pop-up window. Then check the Regular expressions check box.
Use these Regex in the Find and Replace with textboxes respectively.
Find: <(.*?)name\s*=\s*\"([^"]*)\"(.*)/>
Replace with: <form:\1 \3 path="\2" />
Regex Explanation:
< # starting of the tag
(.*?) # group 1 - all the characters till the word 'name'
name\s*=\s* # the word 'name' and '=' with spaces in between
\" # starting of the name attribute value
([^"]*) # group 2 - the value of name attribute
\" # end of the name attribute value
(.*) # group 3 - all the other attributes and values
/> # end of the tag
This is what I did which does my job.
Find :
<input([^>]*value=")(\$\{([^"]*)\})"([^>]*)
replace with :
<form:input$1$2 path="$3" $4/

Add quotation at the start and end of each line in Notepad++

I have a list (in a .txt file) which I'd like to quickly convert to JavaScript Syntax, so I want to take the following:
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
Black
BlanchedAlmond
and convert it to an array literal...
var myArray = ["AliceBlue", "AntiqueWhite", ... ]
I have the list in notepad++ and I need a reg expression to add the " at the start of the line and ", at the end and remove the line break... does anyone have a quick fix to do this? I'm terrible with RegEx.
I often have to perform such tasks so to know how to do this would be a great benefit to me. Many thanks
You won't be able to do it in a single replacement; you'll have to perform a few steps. Here's how I'd do it:
Find (in regular expression mode):
(.+)
Replace with:
"\1"
This adds the quotes:
"AliceBlue"
"AntiqueWhite"
"Aqua"
"Aquamarine"
"Azure"
"Beige"
"Bisque"
"Black"
"BlanchedAlmond"
Find (in extended mode):
\r\n
Replace with (with a space after the comma, not shown):
,
This converts the lines into a comma-separated list:
"AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond"
Add the var myArray = assignment and braces manually:
var myArray = ["AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond"];
One simple way is replace \n(newline) with ","(double-quote comma double-quote) after this append double-quote in the start and end of file.
example:
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Beige
Replcae \n with ","
AliceBlue","AntiqueWhite","Aqua","Aquamarine","Beige
Now append "(double-quote) at the start and end
"AliceBlue","AntiqueWhite","Aqua","Aquamarine","Beige"
If your text contains blank lines in between you can use regular expression \n+ instead of \n
example:
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Beige
Replcae \n+ with "," (in regex mode)
AliceBlue","AntiqueWhite","Aqua","Aquamarine","Beige
Now append "(double-quote) at the start and end
"AliceBlue","AntiqueWhite","Aqua","Aquamarine","Beige"
Put your cursor at the begining of line 1.
click Edit>ColumnEditor. Put " in the text and hit enter.
Repeat 2 but put the cursor at the end of line1 and put ", and hit enter.
In notepad++, for placing any thing before value
Press CTRL+H
Replace ^ with ' (sign you want append at the start)
Select search mode as Regular Expression
Click Replace All
In notepad++, for placing any thing After value
Press CTRL+H
Replace $ with ' (sign you want to append at the end)
Select search mode as Regular Expression
Click Replace All
Ex: After performing above steps
AHV01 replaced with 'AHV01'
Happy Learning!!
Thanks.
Place your cursor at the end of the text.
Press SHIFT and ->. The cursor will move to the next line.
Press CTRL-F and type , in "Replace with:" and press ENTER.
You will need to put a quote at the beginning of your first text and the end of your last.
I am using Notepad 8.1.9.2 64bit on Windows10, the replacement procedures can be finished in one step, try this:
Find what: (.+)\r\n
Replace with: "\1",
Note: Wrap around and regular express option is selected.
And then you still need to add bracket manually in your code
Thanks!