On VAX/VMS (or OpenVMS Alpha and its other names) there was an editor called TPU. In TPU you could enable selection of text independently of holding a key down. You pressed SELECT and then any cursor movement you made selected text between the editing point and the new cursor location.
You could also record macros. So you could use this text selection feature to create macros like:
find "abc"
select
find "xyz"
cut
stop recording
So this macro would find any line with "abc" in it and then cut all text between "abc" and "xyz". Massive time saver.
Making sense? How can I do that in VS2015? I can't find a macro extension that provides the selection behaviour I need to do this.
Cheers,
.pd.
EDIT
It occurred to me this could be done with a regex but it seems like a pretty big ask.
#Html.DropDownListFor(m => m.Property, Model.SelectListProperty, htmlAttributes: new { #class="whatever" })
// the regex would replace this with
#Html.MyDropDownListFor(m => m.Property, Model.SelectListProperty, Model.Property, htmlAttributes: new { #class="whatever"})
So I would be looking for a regex to
- find #Html.DropDownList
- replace the token 1 of that line split by ',' with token 1 of token 0 split by '.' and prefixed with "Model."
Assuming Model.Property comes from m => m.Property.
Search for
#Html\.DropDownListFor\(((\w+)\s*=>\s*\2\.(\w+)),\s*(Model\.\w+)(,(?:[^(){}]|\{[^{}]*\})*)?\)
Replace with
#Html.MyDropDownListFor($1, $4, Model.$3$5)
Demo: http://regexr.com/3f3io
Related
I have a column in my table which looks like below.
ResourceIdentifier
------------------
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716
arn:aws:glue:us-east-1:5XXXXXX85:devEndpoint/etl-endpoint
i-075656565f7fea3
i-02c3434343f22
qa-271111145-us-east-1-raw
prod-95756565631-us-east-1-raw
prod-957454551631-us-east-1-isin-repository
i-02XXXXXXf0
I want a new column called 'Trimmed Resource Identifier' which looks at ResourceIdentifier and if the value starts with "arn", then returns value after last "/", else returns the whole string.
For eg.
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716 ---> i-09TYTYTY797168
i-02XXXXXXf0 --> i-02XXXXXXf0
How do I do this ? I tried creating a new column called "first 3 letters" by extracting first 3 letters of the ResourceIdentifier column but I am getting stuck at the step of adding conditional column. Please see the image below.
Is there a way I can do all of this in one step using DAX instead of creating a new intermediate column ?
Many Thanks
The GUI is too simple to do exactly what you want but go ahead and use it to create the next step, which we can then modify to work properly.
Filling out the GUI like this
will produce a line of code that looks like this (turn on the Formula Bar under the View tab in the query editor if you don't see this formula).
= Table.AddColumn(#"Name of Previous Step Here", "Custom",
each if Text.StartsWith([ResourceIdentifier], "arn") then "output" else [ResourceIdentifier])
The first three letters bit is already handled with the operator I chose, so all that remains is to change the "output" placeholder to what we actually want. There's a handy Text.AfterDelimiter function we can use for this.
Text.AfterDelimiter([ResourceIdentifier], "/", {0, RelativePosition.FromEnd})
This tells it to take the text after the first / (starting from the end). Replace "output" with this expression and you should be good to go.
I have file A 'Emails' with so many email , and file B 'Domain' with so many domain
Example File A 'Emails ':
ctv#ymail.com
kfi#aol.in
hi#axus.cc
0#gmail.com
igp#yahoo.com
encor#mail2.com
cjang#mail.com
vn#gmail.com
87#gmail.com
ee#maoyt.com
Example file B 'Domain'
#gmail.com
#yahoo.com
My expected result :
0#gmail.com
igp#yahoo.com
vn#gmail.com
87#gmail.com
is there a way to do with 2 file in emeditor .Thanks much
I would propose using the Join CSV function. #Abimanyu's regex method may work if you have less than 10 or so domains. More than that, it might take a while to process the data.
To prepare the document for joining, right click on the CSV/Sort toolbar and edit the User-defined separated format to use # as the delimiter.
Now on both file A and file B, change the CSV mode to User-defined separated. On the CSV/Sort toolbar, there is a button called "Join CSV".
Join CSV options:
Make sure the correct documents are selected
Key Column is the email domain columns
In the list at the bottom, select the output columns, which should be column 1 and 2 from file A
Press the Join Now button, change CSV mode to Normal mode and you will get an output which looks like this:
0#gmail.com
igp#yahoo.com
vn#gmail.com
87#gmail.com
May be this will be help to you :
Pattern : .*#gmail.com|.*#yahoo.com
Match groups:
Match 1
1. 0#gmail.com
Match 2
1. igp#yahoo.com
Match 3
1. vn#gmail.com
Match 4
1. 87#gmail.com
https://rubular.com/r/M3MVSoRj6qnSbl
on oneButtonClicked_(sender)
set faceNumber's setStringValue() to faceNumber's stringValue() & "1"
end oneButtonClicked_
I get this error: "Can’t make «class ocid» id «data optr000000000058B37BFF7F0000» into type list, record or text. (error -1700)"
faceNumber is a label and when the user clicks the button, I want to add string of "1" to it. So for example, if the user clicked the button 5 times
stringValue returns an NSString(wrong answer) CFString. You have to make a real AppleScript String to use it.
BTW your code set faceNumber's setStringValue() is not correct. The reasons are:
The Cocoa handlers are always using the underscore.
If you use the setter setStringValue() you don't need to use set x to
If you want to use setStringValue() you must give the parameter between the parentheses
Now put everything together:
on oneButtonClicked_(sender)
faceNumber's setStringValue_((faceNumber's stringValue) as string & "1")
end oneButtonClicked_
or (to have it clearer):
on oneButtonClicked_(sender)
tell faceNumber
set currentValue to (its stringValue) as string
setStringValue_(currentValue & "1")
end tell
end oneButtonClicked_
I hope you like the answer, after pressing the button twice you have an 11 at the end of the label.
Cheers, Michael / Hamburg
I am attempting to write a script that collects user input using getopts. I need to be able to limit restrict the values the user can enter. I see how to set a default value but, I have been unable to find any way to set a list of allowed values... so,
I am attempting to use Config::Simple to create an array from values stored in a text file to use to validate against.
contents of values.txt
ChangeCategories resolution, storm
contents of main.pl
#---create array from values.txt ChangeCategories
my #chg_cats = $cfg->param("ChangeCategories");
unlink $_ for #chg_cats;
#----grab user input via getopts
my $change_categories = $opt_c || die "Please enter a valid change category; #chg_cats";
The issue occurs when I attempt to do the pattern match, it is matching only the first value listed on the ChangeCategories line in the values.txt file.
#---pattern mathching code
my $valid_category;
chomp(#chg_cats);
foreach (#chg_cats) {
##foreach my $line (#chg_cats) {
if(($_ =~ $change_categories) )
#if(($_ =~ m/$change_categories/) )
#if(($_ eq $change_categories) )
As you can see, I have tried numerous constructs to correct this and verify that I get correct matching results every time. I am not sure if this is somehow related to 'chomping' but, I have tried every pattern I can think of. I am a beginner to Perl and would very much appreciate any and all help.... and if anyone can tell me an easier/cleaner way to achieve this result, I would be very grateful
Is it possible to create rules in Outlook 2007 based on a regex string?
I'm trying to add a filter for messages containing a string such as: 4000-10, a four digit number followed by a dash and then a two digit number, which can be anything from 0000-00 to 9999-99.
I was using this as a regex: \b[0-9]{4}\-[0-9]{2}\b but the filter isn't working. I've tried a few other modifications as well with no luck. I wasn't able to find anything concrete online about whether Outlook even supports entering regexes into a rule, though, so I figured I would ask here in case I'm wasting my time.
EDIT: Thanks to Chris's comment below, I was able to implement this filter via a macro. I thought I would share my code below in case it is able to help anyone else:
Sub JobNumberFilter(Message As Outlook.MailItem)
Dim MatchesSubject, MatchesBody
Dim RegEx As New RegExp
'e.g. 1000-10'
RegEx.Pattern = "([0-9]{4}-[0-9]{2})"
'Check for pattern in subject and body'
If (RegEx.Test(Message.Subject) Or RegEx.Test(Message.Body)) Then
Set MatchesSubject = RegEx.Execute(Message.Subject)
Set MatchesBody = RegEx.Execute(Message.Body)
If Not (MatchesSubject Is Nothing And MatchesBody Is Nothing) Then
'Assign "Job Number" category'
Message.Categories = "Job Number"
Message.Save
End If
End If
End Sub
I do not know if a regex can be used directly in a rule, but you can have a rule trigger a script and the script can use regexes. I hate Outlook.
First, you have to open the script editor via Tools - Macro - Open Visual Basic Editor (Alt-F11 is the shortcut).
The editor will open. It should contain a project outline in a small panel in the top-left corner. The project will be listed as VBAProject.OTM. Expand this item to reveal Microsoft Office Outlook Objects. Expand that to reveal ThisOutlookSession. Double-click ThisOutlookSession to open the code editing pane (which will probably be blank).
Next select Tools menu | References and enable the RegExp references called something like "Microsoft VBScript Regular Expressions 5.5"
You can now create a subroutine to perform your filtering action. Note that a subroutine called by a rule must have a single parameter of type Outlook.MailItem. For example:
' note that Stack Overflow's syntax highlighting doesn't understand VBScript's
' comment character (the single quote) - it treats it as a string delimiter. To
' make the code appear correctly, each comment must be closed with another single
' quote so that the syntax highlighter will stop coloring everything as a string.'
Public Enum Actions
ACT_DELIVER = 0
ACT_DELETE = 1
ACT_QUARANTINE = 2
End Enum
Sub MyNiftyFilter(Item As Outlook.MailItem)
Dim Matches, Match
Dim RegEx As New RegExp
RegEx.IgnoreCase = True
' assume mail is good'
Dim Message As String: Message = ""
Dim Action As Actions: Action = ACT_DELIVER
' SPAM TEST: Illegal word in subject'
RegEx.Pattern = "(v\|agra|erection|penis|boner|pharmacy|painkiller|vicodin|valium|adderol|sex med|pills|pilules|viagra|cialis|levitra|rolex|diploma)"
If Action = ACT_DELIVER Then
If RegEx.Test(Item.Subject) Then
Action = ACT_QUARANTINE
Set Matches = RegEx.Execute(Item.Subject)
Message = "SPAM: Subject contains restricted word(s): " & JoinMatches(Matches, ",")
End If
End If
' other tests'
Select Case Action
Case Actions.ACT_QUARANTINE
Dim ns As Outlook.NameSpace
Set ns = Application.GetNamespace("MAPI")
Dim junk As Outlook.Folder
Set junk = ns.GetDefaultFolder(olFolderJunk)
Item.Subject = "SPAM: " & Item.Subject
If Item.BodyFormat = olFormatHTML Then
Item.HTMLBody = "<h2>" & Message & "</h2>" & Item.HTMLBody
Else
Item.Body = Message & vbCrLf & vbCrLf & Item.Body
End If
Item.Save
Item.Move junk
Case Actions.ACT_DELETE
' similar to above, but grab Deleted Items folder as destination of move'
Case Actions.ACT_DELIVER
' do nothing'
End Select
End Sub
Private Function JoinMatches(Matches, Delimeter)
Dim RVal: RVal = ""
For Each Match In Matches
If Len(RVal) <> 0 Then
RVal = RVal & ", " & Match.Value
Else
RVal = RVal & Match.Value
End If
Next
JoinMatches = RVal
End Function
Next, you have to create a rule (Tools - Rules and Alerts) to trigger this script. Click the New Rule button on the dialog to launch the wizard. Select a template for the rule. Choose the "Check messages when they arrive" template from the "Start from a blank rule" category. Click Next.
Choose the "On this machine only" condition (intuitive isn't it?) and click next.
Choose the "run a script" option. At the bottom of the wizard where it shows your new rule, it should read:
Apply this rule after the message arrives
on this machine only
run a script
The phrase "a script" is a clickable link. Click it and Outlook will display a dialog that should list the subroutine you created earlier. Select your subroutine and click the OK button.
You can click Next to add exceptions to the rule or click Finish if you have no exceptions.
Now, as though that process was not convoluted enough, this rule will deactivate every time you stop and restart Outlook unless you sign the script with a code signing key.
If you don't already have a code signing key, you can create one with OpenSSL.
Did I mention that I hate Outlook?
Microsoft Outlook does not support regular expressions. You can perform wildcard searches, although for some inexplicable reason the wildcard character is %, not *.