I have data that looks like this:
[Shift]);[Ctrl][Ctrl+S][Left mouse-click][Backspace][Ctrl]
I want to find all [.*] tags that have the word mouse in them. Keeping in mind non-greedy specifiers, I tried this in Vim: \[.\{-}mouse.\{-}\], but this yielded this result,
[Shift]);[Ctrl][Ctrl+S][Left mouse-click]
Rather than just the desired,
[Left mouse-click]
Any ideas? Ultimately I need this pattern in Perl syntax as well, so if anyone has a solution in Perl that would also be appreciated.
\[[^]]*mouse[^[]*\]
That is, match a literal opening bracket, then any number of characters that aren't closing brackets, then "mouse," then any number of non-opening-brackets, and finally a literal closing bracket. Should be the same in Perl.
You can use the following regex:
\[[^\]]*mouse.*?\]
Related
I'm extracting case numbers from a wall of text. How do I filter out all the useless text using the replace function in Notepad++ with the help of RegEx? The parts I want to keep are made up of letters, digits, and a hyphen (SPP-1803-2045227).
I would like to turn this...
(SPP-1803-2045227)Useless text goes here. 2019-05-18 *
(SPP-1915-1802667)More useless text. 2019-01-14 *
(SPP-1904-1012523)And some more. 2019-02-03 *
...into this:
SPP-1803-2045227
SPP-1915-1802667
SPP-1904-1012523
I've been playing around with RegEx and also found something in another thread on here before, which wasn't the solution but came very close. Unfortunately I can't find it anymore. It looked something like this:
^(?!S\w+).*\r?\n?
Any help is appreciated.
you could try something like this.
find: .*\((\w{3}-\d{4}-\d{7})\).*
replace with: \1
The above Regular Expression matches the whole line with your letters and digits between an extra pair of parentheses.
When you replace with \1 you keep only the match between parentheses.
Remember to select Regular Expression Search mode.
I have an example string:
*DataFromAdHoc(cbgv)
I would like to extract by RegEx:
DataFromAdHoc
So far I have figured something like that:
^[^#][^\(]+
But Unfortunately without positive result. Do you have maybe any idea why it's not working?
The regex you tried ^[^#][^\(]+ would match:
From the beginning of the string, it should not be a # ^[^#]
Then match until you encounter a parenthesis (I think you don't have to escape the parenthesis in a character class) [^\(]+
So this would match *DataFromAdHoc, including the *, because it is not a #.
What you could do, it capture this part [^\(]+ in a group like ([^(]+)
Then your regex would look like:
^[^#]([^(]+)
And the DataFromAdHoc would be in group 1.
Use ^\*(\w+)\(\w+\)$
It just gets everything between the * and the stuff in brackets.
Your answer may depend on which language you're running your regex in, please include that in your question.
In Vim, a search and replace command which to the segment below:
func {print("touching curly braces")}
transforms it into this:
func { print("touching curly brace") }
So far I have:
:%s/{.\( \)\#!/{./g
However, it does this to the first segment:
func {.rint("touching curly braces")}
I believe I need something like this:
:%s/{.\( \)\#!/{ ./g
:%s/}.\( \)\#!/} ./g
How do I replace the kleene star '.' with the character it matched?
You need to put the . into a group so you can repeat in the substituion string \(.\)
:%s/{\(.\)\( \)\#!/{ \1/g
:%s/}\(.\)\( \)\#!/} \1/g
This is what is called backreferencing and grouping
If you want to do both spaces at once here is the command:
:%s/{\(\S.*\S\)}/{ \1 }/g
I'd replace
:%s/{\($| \)\#!/{ /g
and
:%s/\(^| \)\#<!}/ }/g
where {\($| \)\#! is { and a negative lookahead for either end-of-line or space, the other expression is analogous with a negative lookbehind and }.
Note that replacing in source code like that is a dangerous endeavor. You can break things very easily. Think of curly braces inside strings, or in regular expressions, or other situations you did not quite think of. Use /gc instead of /g to manually confirm each change.
do you mean this? I hope I understood your problem right:
s/\zs{\ze./& /g
s/.\zs}\ze/ &/g
You can do it in this way too:
s/{\ze./& /g
s/.\zs}/ &/g
In Autoit script Iam unable to do Regular expression for the below string Here the numbers will get changed always.
Actual String = _WinWaitActivate("RX_IST2_AM [PID:942564 NPID:10991 SID:498702881] sbivvrwm060.dev.ib.tor.Test.com:30000","")
Here the PID, NPID & SID : will be changing and rest of the things are always constant.
What i have tried below is
_WinWaitActivate("RX_IST2_AM [PID:'([0-9]{1,6})' NPID:'([0-9]{1,5})' SID:'([0-9]{1,9})' sbivvrwm060.dev.ib.tor.Test.com:30000","")
Can someone please help me
As stated in the documentation, you should write the prefix REGEXPTITLE: and surround everything with square brackets, but "escape" all including ones as the dots (.) and spaces () with a backslash (\) and instead of [0-9] you might use \d like "[REGEXPTITLE:RX_IST2_AM\ \[PID:(\d{1,6})\ NPID:(\d{1,5})\ SID:(\d{1,9})\] sbivvrwm060\.dev\.ib\.tor\.Test\.com:30000]" as your parameter for the Win...(...)-Functions.
You can even omit the round brackets ((...)) but keep their content if you don't want to capture the content to process it further like with StringRegExp(...) or StringRegExpReplace(...) - using the _WinWaitActivete(...)-Function it won't make sense anyways as it is only matching and not replacing or returning anything from your regular expression.
According to regex101 both work, with the round brackets and without - you should always use a tool like this site to confirm that your expression is actually working for your input string.
Not familiar with autoit, but remember that regex has to completely match your string to capture results. For example, (goat)s will NOT capture the word goat if your string is goat or goater.
You have forgotten to add a ] in your regex, so your pattern doesn't match the string and capture groups will not be extracted. Also I'm not completely sold on the usage of '. Based on this page, you can do something like StringRegExp(yourstring, 'RX_IST2_AM [PID:([0-9]{1,6}) NPID:([0-9]{1,5}) SID:([0-9]{1,9})]', $STR_REGEXPARRAYGLOBALMATCH) and $1, $2 and $3 would be your results respectively. But maybe your approach works too.
I have a string like
{! texthere }
I want to capture either everything after {! until either the end or you reach the first }. So if I had
{!text here} {!text here again} {!more text here. Oh boy!
I would want ["{!text here}", "{!text here again}", "{!more text here. oh boy!"]
I thought this would work
{!.*}??
but the above string would come out to be ["{!text here} {!text here again} {!more text here. Oh boy!"]
I'm still very inexperienced with regexes so I don't understand why this doesn't work. I would think it would match '{!' followed by any number of characters until you get to a bracket (non greedy) which may not be there.
Using positive lookbehind (?<={!)[^}]+:
In [8]: import re
In [9]: str="{!text here} {!text here again} {!more text here. Oh boy!"
In [10]: re.findall('(?<={!)[^}]+',str)
Out[10]: ['text here', 'text here again', 'more text here. Oh boy!']
That is positive lookbehind where by any non } character is matched if following {!.
You can do it this way :
({![^}]+}?)
Edit live on Debuggex
Then recover the capture group $1 which corresponds to the first set of parenthesis.
Using this way, you have to use a "match all" type of function because the regex itself is made to match a single group function
This way doesn't use any look around. Also the use of ^} should limit the number of regex engine cycle since it is searching for the next } as a breaker instead of having to do the whole expression then backtrack.
I believe you want to use a reluctant quantifier:
{!.*?}?
This will cause the . to stop matching as soon as the first following } is found, instead of the last.
I had a question about greedy and reluctant quantifiers that has a good answer here.
Another option would be to specify the characters that are allowed to come between the two curly braces like so:
{![^}]*}?
This specifies that there cannot be a closing curly brace matched within your pattern.
if your tool/language supports perl regex, try this:
(?<={!)[^}]*