Application Insights - regex flags - regex

I made this very simple regex
extract("ProductCode",0,message)
And of course it's working but I have no idea how to make it case-insensitive. I tried to add 'i' flag like this
extract("productcode/i",0,message)
or like this
extract("/productcode/i",0,message)
nothing works.. no idea what I'm doing wrong. Please help

You can try the following syntax:
(?i)productcode(?-i)
This will make that part of your regex case insensitive.
You can dismiss the (?-i) if you want to apply it to the whole regex.
Good luck.

Related

Regex for searching inside a string

I am not really good at regex.
Can someone help me with generating regex regarding this problem:
If I input lets say "an"
It should match Annie but not Stan or Jan.
I will just use the regex in my searching module.
Thanks.
\ban\B
You can use this.\b will make sure word starts with an and \B will makee sure it does not end with an.TO make it case sensitive use i flag.
or
\b[aA][nN]\B
You can use this:
^a|An
It is case insensitive
^an
Would match any string starting with an "an".
Answering your comment on the case sensitivity, it would depend on the regex parser. Ex with grep you can pass the -i flag.
There can be multiple ways to achieve it.
However, I would suggest you to spend only 30 minutes on http://regexone.com. Get some hands on it. This will really help to get head start on Regex.

Issues with RegEx

I am trying to make an if-then-else statement using RegEx. I want to match the text if it contains Monty and also contains Python. Also the text should get matched if Monty is not present in the text.
RegEx
(?(?=Monty)(?(?=Python).*|)|^.*).*$
Kindly help!
How about this:
(^(?!.*Monty(?!.*Python.*).*).*$|^.*Python.*Monty.*$)
This passes my tests, but let me know if it works for you.
I am not versed in lookahead regex but just tried to build the regex from what I understood from above description. Check the link to see if this is what you are trying to do.
try this instead
((?=Monty)((?=Python).*|)|^.*).*$

I need some help doing a regular expression

I'm using netbeans and I want to wrap $this->escape(stuff) around specific stuff in more files, using the replace feature, but there's plenty of conditions, like:
match:
$this->$variable, $variable
$this->$array['something'], $this->$array[0], $array['something'], $array[0]
do not match:
$this->partial, $this->escape, $this->form
What I have so far that works ok
replace this
echo\s+(\$this->[->a-zA-Z_']+[^\s;(])
with this
echo \$this->escape\($1\)
It doesn't work with arrays and doesn't exclude anything, also doesn't match $variable
Could anyone help out, improve the expression so that it would reduce the torture of going through so many strings by hand? Any help is appreciated.
edit: just adding the exclusions to my working example would be enough.
It's not entirely clear what parts you're trying to match. If I understood you correctly then this should work:
(?:\$this->)?\$[^,\s-]*(?=[,\s])
If you meant to match something else, please let me know.

a simple (i think) REGEX needed for Textmate

Can someone please advise how to do this search and replace in textmate. I think I need a REGEX (but i know very little about REGEXes!)
i want to change all these bullet images to GIFs...
bullet-1.png
becomes
bullet-1.gif
and I want where the number is to be a wildcard
The regular expression:
bullet-(\d+).png
The replacement:
bullet-$1.gif

Regex - match a string not contain a 'semi-word'

I tried to make regex syntax for that but I failed.
I have 2 variables
PlayerInfo[playerid][pLevel]
and
Character[playerid]
and I want to catch only the second variable,I mean only the world what don't contain PlayerInfo, but cointains [playerid]
"(\S+)\[playerid\]" cath both words and (\S+[^PlayerInfo])\[playerid\] jump on some variables- they contais p,l,a,y ...
I need to replace in notepad++,all variables like Text[playerid] to ExClass [playerid][Text]
Couple Pluasible solutions.
List item
Notepad has a plugin called python script. Running regex from there
gives full regex functionality, the python version anyway, and a lot
of powerful potential beyond that. And I use the online python regex tester to help out.
RegRexReplace plugin helps create regex plugins in Notepad++, so when you do hit a limitation, you find out a lot quicker.
Or of course default to your alternate editor (I'm assuming you have
one?) or this online regex tool is absolutely amazing. You
can perform the action on the text online as well.
(I'd try to build a regex for you, but I'm a bit lost as to what you're looking for. Unless the Ivo Abeloos got it. If you're still coming up short, maybe a code example along with values displayed?)
Good luck!
It seems that Notepad++ support negative lookbehind since v6.
In notepad++ you could try to replace (.+)\[(.+)\] with ExClass\[\2\]\[\1\]
Try to use negative lookbehind.
(?<!PlayerInfo)\[playerid\]
EDIT: unfortunately notepad++ does not support negative lookbehind.
I tried to make a workaround based on the following naive idea:
(.[^o]|[^f]o)[playerid]
But this expression does not work either. Notepad++ seems to fail in alternative operator. Thus the answer is: it is impossible to do exactly what you want. Try to solve the problem in other way or use alternative tool.