Exclude words with numbers from spellcheck in vim - regex

Following a similar answer I would like to ignore words with numbers that are of the following format:
AB12
AB2
CD98
..
this is achieved with use of the following regex:
[A-Z]{2}\d{1,}
(regex101)
The syntax I'm trying:
:syn match ignoredCapitalWords +[A-Z]{2}\d{1,}+ contains=#NoSpell
does not seem to be generating the desired results as the words remain marked as potentially misspelled:
How can I correctly used the previously generated regex to exclude the desired patterns from regex?

Php regex engine is not vim regex engine. When you doubt your syntax pattern is right just create a new buffer with desired contents and then use / command. The given pattern throws an error, you just have to escape each { character with backslash. So, the correct pattern is: [A-Z]\{2}\d\{1,}. Never used #NoSpell but the pattern works.

Related

Regular Expression - Starting and ending with, and contains specific string in the middle

I would like to generate a regex with the following condition:
The string "EVENT" is contained within a xml tag called "SHEM-HAKOVETZ".
For example, the following string should be a match:
<SHEM-HAKOVETZ>104000514813450EVENTS0001dfd0.DAT</SHEM-HAKOVETZ>
I think you want something like this ^<SHEM-HAKOVETZ>.*EVENT.*<\/SHEM-HAKOVETZ>$
Regular expression
^<SHEM-HAKOVETZ>.*EVENTS.*<\/SHEM-HAKOVETZ>$
Parts of the regular expression
^ From the beginning of the line
<SHEM-HAKOVETZ> Starting tag
.* Any character - zero or more
EVENT Middle part
<\/SHEM-HAKOVETZ>$ Ending part of the match
Here is the working regex.
If you want to match this line, you could use this regex:
<SHEM-HAKOVETZ>*EVENTS.*(?=<\/SHEM-HAKOVETZ>)
However, I would not recommend using regex XML-based data, because there may be problems with whitespace handling in XML (see this article for more information). I would suggest using an actual XML parser (and then applying the reg to be sure about your results.
Here is a solution to only match the "value" part ignoring the XML tags:
(?<=<SHEM-HAKOVETZ>)(?:.*EVENTS.*)(?=<\/SHEM-HAKOVETZ>)
You can check it out in action at: https://regex101.com/r/4XiRch/1
It works with Lookbehind and Lookahead to make sure it will only match if the tags are correct, but for further coding will only match the content.

Regex expression to exclude both prefix and suffix

I'm trying to build an expression which will match all text EXCLUDING text with prefix 'abc' AND suffix 'def' (text which only has the prefix OR the suffix is ok).
I've tried the following:
^(?!([a][b][c]])).*(?!([d][e][f])$), but it doesn't match text which only has one of the criterias (i.e. abc.xxx fails, as well as xxx.pdf, though they should pass)
I understand the answer is related to 'look behind' but i'm still not quite sure how to achieve this behavior
I've also tried the following:
^(?<!([a][b][c])).*(?!([d][e][f])$), but again, with no luck
^((abc.*\.(?!def))|((?!abc).*\.def))$
I think there can be a simpler solution, but this one will work as you wanted it.
[a][b][c] can be simplified to abc, the same goes for def.
The first part of the pattern matches abc.*\. without def at the end.
The second part matches .*\.def without the prefix abc.
Here is a visual representation of the pattern:
Debuggex Demo
Keep it simple and combine it into a single lookahead to check both conditions:
^(?!abc.*def$).*

Using regex to replace all except specific string form

I'm looking to pull data from some code, to do that I thought I could use regex.
An example of the code I have is:
If IsNumeric(varCS) And IsNumeric(varGTV) And IsNumeric(varTV) Then
logInfo("GO")
shtDst.Range("D6").Value = shtSrc.Cells(varCS, varGTV).Value
shtDst.Range("G104").Value = shtSrc.Cells(varCS, varTV).Value
I would like the result to be:
"D6"
"G104"
The regex I've tried is:
.*(?:Range\((.*)\))?.*
and replacing with:
\1
However this results in just blank lines.
I've looked at lookahead and lookbehind but those seem to require a fixed length string.
I've been using Notepad++ plus various online regex test sites to verify my results.
Have a try with (don't make Range... optional):
Ctrl+H
Find what: ^(?:.*?Range\((.+?)\).*?|.+)$
Replace with: $1
This is working with the given example.
Try replacing [\S\s]*?("[^"]*?").* with $1\r\n (Example)

How do I craft a regular expression to exclude strings with parentheses

I have the following SDDL:
O:BAG:BAD:(A;;CCDCLCSWRP;;;BA)(A;;CCDCSW;;;WD)(A;;CCDCLCSWRP;;;S-1-5-32-562)(A;;CCDCLCSWRP;;;LU)(A;;CCLCRP;;;S-1-5-21-4217728705-3687557540-3107027809-1003)
Unfortunately I keep getting this:
(A;;CCDCLCSWRP;;;BA)(A;;CCDCSW;;;WD)
And what I want is just (A;;CCDCSW;;;WD).
My regex is: (\(A;.+;WD\)) : find "(A;" some characters ending in ";WD)"
I've tried making the match lazy and I've tried excluding the ")(" pair of characters based on a search of the stackoverflow regex tag looking for examples where others have answered similar questions.
I'm really confused why the exclusion of the parens isn't working:
(\(A;.+[^\(\)]*.+;WD\)) : find "(A;" followed by some characters where none of them are ")('' followed by other characters ending in ";WD)"
And this was my guess at using negative look around:
(\(A;.+^((?!\)\().).+;WD\))
which didn't match anything.
I'm also doing this in PowerShell v3.0 with the following code:
$RegExPattern = [regex]"(\($ACE_Type;.*;$ACE_SID\))+?"
if ($SDDL -match $RegExPattern) {
$MatchingACE = $Matches[0]
Where in this instance $ACE_Type = "A" and $ACE_SID = "WD".
You almost had the solution with your second regex pattern. The problem was that you included too many . wildcards. This should be all you need:
A;[^()]+;WD
And of course if you just want to capture the string in between A; and ;WD:
A;([^()]+);WD
Then just replace with \1.
I simplified this a lot and then added lookarounds so that you only matched the intended string (in between A;...;WD). This looks behind for A;, then matches 1+ non-parenthesis characters, while looking ahead for ;WD.
(?<=A;)[^()]+(?=;WD)
Regex101

re2 does not seem to give correct results for some patterns when compared to pcre

I was trying to use both pcre and re2 and I came up with the following observation.
When I give the string as
"ab cd"
and the pattern as
"^[^c]"
re2 returns NO MATCH but its actually a match.
That is to say when I type this RE2::FullMatch("ab cd", RE2("^[^c]")) I get FAIL/No Match.
Please let me know if I am going wrong somewhere or what is the problem?
RE2::FullMatch matches the entire string, like Jerry says.
There are two basic operators: RE2::FullMatch requires the regexp to
match the entire input text, and RE2::PartialMatch looks for a match
for a substring of the input text, returning the leftmost-longest
match in POSIX mode and the same match that Perl would have chosen in
Perl mode.
https://code.google.com/p/re2/wiki/CplusplusAPI