Regexp - exclude pattern using negative lookahead [duplicate] - regex

This question already has answers here:
Webpack regex test that matches *.ts but not *.d.ts
(1 answer)
Regex: match everything but a specific pattern
(6 answers)
Closed 2 years ago.
I've inside my company a deployment process called XL-Deploy.
XL-Deploy give me possibility to replace some mustach variable by value stored in XL-Deploy library
like Jenkins for comparison.
My problem with this application come with file extension. Yes, XL-Deploy need to specify using regexp wich file type need to be scan for variable replacement.
I'm not a pro with regexp but my company give me this regexp work perfectly when file are basic (foo.bar, index.php, test.html, etc..) but in my case not working because my config file name is config.ini.php.
I've try 1 day without success to create regexp working for exclude my config.ini.php.
Original work regexp for all file following this pattern: index.html, test.php, foo.bar
(.+.(?!php).*)
I've try (.+.(?!ini\.php).*) but for an unknow reason i dont understand when i add dot in negative lookahead my group stop working, because i need a matching for config.ini.php.
Thank you in advance for your help really needed :)
Have a good dev
William

Related

Regex pattern to find text either of two URLs [duplicate]

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 2 years ago.
I have the following regex:
(?<=unit/)(.*)(?=/)
I use it to get a page name between unit and the guid.
www.page.com/module/unit/design/6e8c1d2b-34vc-4b5c-71af-8b0f93b01b60?sid=5fh6y172-31d9-4r6b-9a15-daed6c541162&culture=en-US
Now i am receiving an URL like this, with /load before the sid.
www.page.com/module/unit/design/6e8c1d2b-34vc-4b5c-71af-8b0f93b01b60/load?sid=5fh6y172-31d9-4r6b-9a15-daed6c541162&culture=en-US
so i am getting this result from the regex
design/6e8c1d2b-34vc-4b5c-71af-8b0f93b01b60
How can i change the regex in order to get just design, moreover how can i create a regex that find design either or both URLs?
Instead of .* use [^/]* to match any sequence of characters not including /. This will get everything until the next /.
(?<=unit/)[^/]*

Replacing a certain number of characters after a match in regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I want to find any instance of
\/Network\/Cambric Corporate Center\/
and replace the next 8 characters with nothing.
So something like this
\/Network\/Cambric Corporate Center\/1164.DEV1164
Turns into this
\/Network\/Cambric Corporate Center\/1164
I'm working with a baked in replace regular expression visual programming piece, and this is my first post to here ever so please ask if more info is needed. I basically just need it to look like this
\/Network\/Cambric Corporate Center\/1164
if there is another solution without having to use replace
It is for a frequently updated mass source of data that I need to edit to make more compatible with arrays
Try (\/Network\/Cambric Corporate Center\/).{8} and replace with $1 to keep the first group but not anything else.
Here's the regex with the replacement: https://regex101.com/r/F4Y4VD/1

Match rest of string with Regex in Notepad++ [duplicate]

This question already has answers here:
How to remove everything after a certain character? (notepad++)
(2 answers)
Closed 3 years ago.
I have the following json file:
[{"accountId":"fe1a8715-794b-4fd9-84df-ccbc7dd1c0c6","id":"9314c53324","state":"Processed","moderationState":"OK","reviewState":"None","privacyMode":"Private","processingProgress":"100%","failureCode":"None","failureMessage":"","externalId":null,"externalUrl":null,"metadata":null,"insights":{"version":"1.0.0.0","duration":"0:00:20.6","sourceLanguage":"en-US","sourceLanguages":["en-US"],"language":"en-US","languages":["en-US"],"labels":[{"id":1,"name":"outdoor","language":"en-US","instances":[{"confidence":0.9964,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.9981,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9966,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"},{"confidence":0.969,"adjustedStart":"0:00:17.067","adjustedEnd":"0:00:20.6","start":"0:00:17.067","end":"0:00:20.6"}]},{"id":2,"name":"mountain","referenceId":"geological formation/natural elevation/mountain","language":"en-US","instances":[{"confidence":0.9574,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.99,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9797,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"}]},{"id":3,"name":"snow","referenceId":"natural phenomenon/weather/snow","language":"en-US","instances":[{"confidence":0.9755,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.998,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.991,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"},{"confidence":0.9788,"adjustedStart":"0:00:19.2","adjustedEnd":"0:00:20.6","start":"0:00:19.2","end":"0:00:20.6"}]},{"id":4,"name":"nature","referenceId":"nature","language":"en-US","instances":[{"confidence":0.9946,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.9959,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9792,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"},{"confidence":0.8443,"adjustedStart":"0:00:17.067","adjustedEnd":"0:00:19.2","start":"0:00:17.067","end":"0:00:19.2"}]},{"id":5,"name":"valley","language":"en-US","instances":[{"confidence":0.8591,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.9502,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9092,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"}]},{"id":6,"name":"canyon","referenceId":"geological formation/natural depression/canyon","language":"en-US","instances":[{"confidence":0.8353,"adjustedStart":"0:00:06.4","adjustedEnd":"0:00:08.533","start":"0:00:06.4","end":"0:00:08.533"}]},{"id":7,"name":"covered","language":"en-US","instances":[{"confidence":0.8697,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:14.933","start":"0:00:10.667","end":"0:00:14.933"}]}],"scenes":[{"id":1,"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"shots":[{"id":1,"tags":["Outdoor"],"keyFrames":[{"id":1,"instances":[{"thumbnailId":"a137ab2a-f250-4ace-a71f-8a158517863b","adjustedStart":"0:00:00.4","adjustedEnd":"0:00:00.467","start":"0:00:00.4","end":"0:00:00.467"}]},{"id":2,"instances":[{"thumbnailId":"52d41f10-20e7-40c4-9426-d2482fd6ec71","adjustedStart":"0:00:16.667","adjustedEnd":"0:00:16.734","start":"0:00:16.667","end":"0:00:16.734"}]}],"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"blocks":[{"id":0,"instances":[{"adjustedStart":"0:00:00","adjustedEnd":"0:00:20.6","start":"0:00:00","end":"0:00:20.6"}]}],"textualContentModeration":{"id":0,"bannedWordsCount":0,"bannedWordsRatio":0,"instances":[]},"statistics":{"correspondenceCount":0,"speakerTalkToListenRatio":{},"speakerLongestMonolog":{},"speakerNumberOfFragments":{},"speakerWordCount":{}}},"thumbnailId":"116bfb86-5a32-41a3-9fda-2417beb52a18","detectSourceLanguage":false,"languageAutoDetectMode":"None","sourceLanguage":"en-US","sourceLanguages":["en-US"],"language":"en-US","languages":["en-US"],"indexingPreset":"Default","linguisticModelId":"00000000-0000-0000-0000-000000000000","personModelId":"00000000-0000-0000-0000-000000000000","isAdult":false,"publishedUrl":"https://rodmandev.streaming.mediaservices.windows.net/0c4d34a3-4415-4f56-a4e5-7b34292eb72d/DJI_0043mp4.sil.ism/manifest(encryption=cbc)","publishedProxyUrl":null,"viewToken":"Bearer=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cm46bWljcm9zb2Z0OmF6dXJlOm1lZGlhc2VydmljZXM6Y29udGVudGtleWlkZW50aWZpZXIiOiIyNWI5OTRiOC03NzQyLTQ2MmUtOWExMy0zMTYwMzMwNWQzOGQiLCJuYmYiOjE1NzY1MDQxNTUsImV4cCI6MTU3NjU0NzQxNSwiaXNzIjoiaHR0cHM6Ly9icmVha2Rvd24ubWUiLCJhdWQiOiJCcmVha2Rvd25Vc2VyIn0.KAvVIh7dlFqbELqv2wwHJZocHonIXOZCvff20t3KWKg"}]
I'm trying to remove all the text except the words in quotes that come after "name".
In Notepad++, using the find and replace function, I searched for .+?name":"(.+?)" and replaced it with \1.
That returns the following result:
outdoor mountain snow nature valley canyon covered ,"language":"en-US","instances":[{"confidence":0.8697,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:14.933","start":"0:00:10.667","end":"0:00:14.933"}]}],"scenes":[{"id":1,"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"shots":[{"id":1,"tags":["Outdoor"],"keyFrames":[{"id":1,"instances":[{"thumbnailId":"a137ab2a-f250-4ace-a71f-8a158517863b","adjustedStart":"0:00:00.4","adjustedEnd":"0:00:00.467","start":"0:00:00.4","end":"0:00:00.467"}]},{"id":2,"instances":[{"thumbnailId":"52d41f10-20e7-40c4-9426-d2482fd6ec71","adjustedStart":"0:00:16.667","adjustedEnd":"0:00:16.734","start":"0:00:16.667","end":"0:00:16.734"}]}],"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"blocks":[{"id":0,"instances":[{"adjustedStart":"0:00:00","adjustedEnd":"0:00:20.6","start":"0:00:00","end":"0:00:20.6"}]}],"textualContentModeration":{"id":0,"bannedWordsCount":0,"bannedWordsRatio":0,"instances":[]},"statistics":{"correspondenceCount":0,"speakerTalkToListenRatio":{},"speakerLongestMonolog":{},"speakerNumberOfFragments":{},"speakerWordCount":{}}},"thumbnailId":"116bfb86-5a32-41a3-9fda-2417beb52a18","detectSourceLanguage":false,"languageAutoDetectMode":"None","sourceLanguage":"en-US","sourceLanguages":["en-US"],"language":"en-US","languages":["en-US"],"indexingPreset":"Default","linguisticModelId":"00000000-0000-0000-0000-000000000000","personModelId":"00000000-0000-0000-0000-000000000000","isAdult":false,"publishedUrl":"https://rodmandev.streaming.mediaservices.windows.net/0c4d34a3-4415-4f56-a4e5-7b34292eb72d/DJI_0043mp4.sil.ism/manifest(encryption=cbc)","publishedProxyUrl":null,"viewToken":"Bearer=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cm46bWljcm9zb2Z0OmF6dXJlOm1lZGlhc2VydmljZXM6Y29udGVudGtleWlkZW50aWZpZXIiOiIyNWI5OTRiOC03NzQyLTQ2MmUtOWExMy0zMTYwMzMwNWQzOGQiLCJuYmYiOjE1NzY1MDQxNTUsImV4cCI6MTU3NjU0NzQxNSwiaXNzIjoiaHR0cHM6Ly9icmVha2Rvd24ubWUiLCJhdWQiOiJCcmVha2Rvd25Vc2VyIn0.KAvVIh7dlFqbELqv2wwHJZocHonIXOZCvff20t3KWKg"}]
The problem is that I don't want to keep any text after covered.
I tried using .+?name":"(.+?)"(\S+) which removed some of the text I want to keep.
How do I fix this?
You should search using a pattern which targets the entire file:
Find: ^.*"name":"(.+?)".*$
Replace: $1
What is currently happening is that your pattern only targets everything up to the literal in quotes appearing after the key name. The content after that is not being replaced.
Demo

trying to match while excluding from front/behind - Eclipse Negative Lookahead not working as I expect it to [duplicate]

This question already has answers here:
Regular expression for a string containing one word but not another
(5 answers)
Closed 3 years ago.
I am trying to write some regex to use in Eclipse file search that will find "http:", while allowing me to exclude a word or words before and after the "http:"
Before making it work for both in front and behind, I am just trying to get it to work excluding phrases in the front using negative lookahead. So I have been trying this:
^(?!QName).*http:
or
.*^(?!QName).*http:
I would expect this line to not come back in the search:
// QName qn = new QName( "http://BUNDLE.wsdl","bundle");
But it does come back in the search. These both match the line all the way up to http: if QName is not present, or it matches the entire line if QName is present.
Eventually I want to make it more complex where I can exclude words in the front and back:
^(?!QName|xlmns).*http:^(?!word1|word2)
But I am far from that point - however any help on that will be appreciated since I am likely going to have trouble with it too
Credit to Wiktor Stribiżew in the above post
^(?!.*(?:QName|xmlns).*http:).*http:

How to exclude files names that have exact match with regex and to support multiple patterns? [duplicate]

This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Alternation operator inside square brackets does not work
(2 answers)
Closed 4 years ago.
I have a program that transfers files from one folder to another (and does some manipulation on those files),
I am trying to create a regex to exclude certain files based on file name and extension, this also needs to support multiple entries that users enter the exclude patterns they want like -
exclude pattern: thumbs.db ; donotmove.xls ; *.ini;
I have a folder with the following c:\testfolder:
test.txt
test.exe
something.jpg
other.pdf
Above should be moved (could be any file)
Below should not be moved (could be anything that the user specifies in config
thumbs.db
donotmove.xlsx
The goal is to exclude unwanted files like thumbs.db, and other files that the user will want to exclude (the code is already written, I am just having trouble with the regex itself).
I have been able to create a regex that will capture thumbs.db, but I have not been able to successfully add a negative lookahead into the regex.
The regex I have is:
^[Tt][Hh][Uu][Mm][Bb][Ss]\.[Dd][Bb]$
this captures thumbs.db exactly meaning if I have a file with this name "tthumbs.db" it should not capture the file name.
first problem I have is not being able to use negative lookhead to exclude the string
I have tried the following:
^(?![Tt][Hh][Uu][Mm][Bb][Ss].[Dd][Bb])$
^(?![Tt][Hh][Uu][Mm][Bb][Ss]).(?![Dd][Bb])$
^(?![Tt])(?![Hh])(?![Uu])(?![Mm])(?![Bb])(?![Ss])).(?![Dd])(?![Bb])$
second problem I have is not being able to correctly use capturing group to capture multiple strings in one regex, I tried to add another capture group but adding does not capture anything
^([Tt][Hh][Uu][Mm][Bb][Ss].[Dd][Bb])([Tt][Ee][Ss][Tt].[Tt][Xx][Tt])$
thnx in advance.