Regular Expression to find all SupressMessage in solution - regex

I am looking for a regular expression to match all references to SuppressMessage in a solution that took over.
example:
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.ToString")]
I tried this to find the SuppressMessage with the beginning and ending square brackets but it does not observe line feeds and when multiple matches are with the same file, it will return the bulk of the file.
\[(SuppressMessage)\((.*)\)\]

[(SuppressMessage)((.*?))]
try it

Thanks vks - That got me closer but that finds two groups.
SupressMessage
"Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0"
What I found that works (without multiple SuppressMessages in the same square brace) is:
\[(SuppressMessage.*?)\]

\[(SuppressMessage\((?:.*?)\))\]
make your expression non greedy.In fact try
\[(SuppressMessage\((?:[^)]*)\))\]
or
\[(SuppressMessage[^)]*\)))
to make it fail proof.

Related

Regex to match everything between multiple set of brackets

I am trying to match everything between multiple set of brackets
Example of data
[[42.30722,-83.181125],[42.30722,-83.18112667],[42.30722167,-83.18112667,[42.30721667,-83.181125],[+42.30721667,-83.181125]]
I need to match everything within the inner brackets as below
42.30722,-83.181125,
42.30722,-83.18112667,
42.30722167,-83.18112667,
42.30721667,-83.181125,
+42.30721667,-83.181125
How do I do that. I tried \[([^\[\]]|)*\] but it gives me values with brackets. Can anybody please help me with this. Thanks in advance
Seems like one of them is missing a bracket maybe, or if not, maybe some expression similar to:
\[([+-]?\d+\.\d+)\s*,\s*([+-]?\d+\.\d+)\s*\]?
might be OK to start with.
Test
import re
expression = r"\[([+-]?\d+\.\d+)\s*,\s*([+-]?\d+\.\d+)\s*\]?"
string = """
[[42.30722,-83.181125],[42.30722,-83.18112667],[42.30722167,-83.18112667,[42.30721667,-83.181125],[+42.30721667,-83.181125]]
"""
print([list(i) for i in re.findall(expression, string)])
print(re.findall(expression, string))
Output
[['42.30722', '-83.181125'], ['42.30722', '-83.18112667'], ['42.30722167', '-83.18112667'], ['42.30721667', '-83.181125'], ['+42.30721667', '-83.181125']]
[('42.30722', '-83.181125'), ('42.30722', '-83.18112667'), ('42.30722167', '-83.18112667'), ('42.30721667', '-83.181125'), ('+42.30721667', '-83.181125')]
If you wish to simplify/modify/explore the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.
A little late, but figured I would include it anyhow.
Your 3rd set is missing a ']'.
If that is in there, then in Alteryx, you can just use Text to Columns splitting to Rows and ignore delimiter in brackets

Google sheets REGEXREPLACE() replace text with itself

In Google Sheets, I'd like to replace the following text:
The ANS consists of fibers that stimulate ((1smooth muscle)), ((2cardiac muscle)), and ((3glandular cells)).
with this text below:
The ANS consists of fibers that stimulate {{c1::smooth muscle}}, {{c2::cardiac muscle}}, and {{c3::glandular cells}}.
I know if I use =REGEXREPLACE(E3, "\(\([0-9]*", "{{c::") I can get here:
The ANS consists of fibers that stimulate {{c::smooth muscle)), {{c::cardiac muscle)), and {{c::glandular cells)).
BUT I don't know how to keep the original numbers
Nvm, figured it out.
Putting parentheses around the term allows you to reference it again in your replacement string.
For example, my solution for my problem was this:
=REGEXREPLACE(E3, "\(\(([0-9]*)", "{{c$1::")
This works because putting [0-9]* in parentheses like so: ([0-9]*) allowed it to be referenced as $1 in my substitution string.
I assume that if I had another phrase enclosed in parentheses after that it would be able to be referenced with $2.
Hope this helps someone in the future.
Pass 1:
Search Pattern:(((\d)(.+)
Replacement:{{C$1::$2
Pass 2:
Search Pattern: ))
Replacment: }}
I played around with it some more and this will do it in one pass:
Search Pattern: \(\((\d)(.+?)\b\)\)
Replacements: {{C$1::$2}}

Regular Expression Repitition groups

I have a Regex :
\*777\*[0-9]{10,}\*\d+\*(5|10|20|25|50|100)\*\d+#
That is what i have these far.
It could handle input : *777*9283928839*89*5*9090#.
The format goes like this : *777*phone*Qty*Item Code*pin#
The problem is sometime the input will go like this :
*777*phone*Qty*Item Code*Qty*Item Code*Qty*Item Code*pin#
It will repeat at Qty*Item Code. But the Item code should be one of these 5,10,20,25,50,100
I confuse in making the regex check for Qty*Item Code.
Can someone give a hint?
Thanks.
You can use the following:
\*777\*[0-9]{10,}\*(\d+\*(5|10|20|25|50|100)\*)+\d+#
Explanation
The part that's repeating seems to be this:
\d+\*(5|10|20|25|50|100)\*
If you enclose that in parentheses and add + after it, it will tell regex to match what's inside the parentheses one or more times:
(\d+\*(5|10|20|25|50|100)\*)+

vim syntax highlighting: match, contains

I am trying to make an angularjs syntax highlighting file for vim. A piece of the file is:
syn match ngMethods /\.[0-9A-Za-z_\-\$]\+\s*\((\|=\)/ contains=AngularMethods
syn keyword AngularMethods contained $addControl $anchorScroll $animate ...
syn match ngObjMethods /^\s*[0-9A-Za-z_\-\$]\+\s*:/ contains=AngularObjectMethods
syn keyword AngularObjectMethods contained compile controller link ...
etc...
Down below I have:
hi def link AngularMethods Function
hi def link AngularObjectMethods Function
The first regular expression (for AngularMethods) is supposed to capture things like $addControl in the following:
myelement.$addControl()
myelement.$addControl = function ()
The second regular expression (for AngularObjectMethods) captures things like compile in:
compile : function () {}
The AngularMethods one does NOT work but the latter one does. Can anyone see the problem? I've also tried using the regexes:
/\.\zs[0-9A-Za-z_\-\$]\+\ze\s*\((\|=\)/
/\.[0-9A-Za-z_\-\$]\+\s*\((\|=\)\#=/
The former matches the exact word. The latter is something I saw in another syntax file. Any ideas? Thanks for your help!
Edit:
Kent (below) was correct about the keyword. This uncovered the real problem which is that I have another regex:
syn match ngProperties /\.[0-9A-Za-z_\-\$]\+\s*[^(=]/ contains=AngularProperties
syn keyword AngularProperties contained $attr $dirty $error ...
which is supposed to be the complement of the ngMethods regex. If I comment out the ngProperties regex, the ngMethods regex works. This means ngProperties is bad. It is supposed to catch things like $attr in:
var myAttribute = element.$attr;
I will try to fix this. Can someone post the correct regex just in case?
The regex is not the problem for your syntax.
What very likely the cause of the problem is, your iskeyword option doesn't have the dollar ($) sign.
what you can test is:
remove the $ from contained $addControl $anchorScrol, to see if it will work
or
execute: set iskeyword+=$ to see if it works.

regular expression match domain

I need a regular expression to match the following domains as follows:
http://www.cnn.com/fred = www.cnn.com
cnn.com = cnn.com
www.cnn.com:8080 = www.cnn.com
I have the following regular expression (using pcre):
([^/]+://)?([^:/]+)
The above works fine in case 2 and 3 however with 1 i still have the http:// appended to the matching string, is there a regular expression option which i can use to skip the http part?
many thanks in advance
This one should suit your needs:
^(?:(?:f|ht)tps?://)?([^/:]+)
The first group will contain what you're looking for.
this looks like the closest i could get to what i want not perfect but seems to gets the job done
www?([^/:]+)