VSCode - Regex to find string excluding others substrings - regex

I have a base classname form my icons, that is i-svg (this is the default icon size).
I have some modifiers to change the size, like i-svg--xs or i-svg--sm.
I need to find only the lines that don't use the modifiers classnames, that is just i-svg.
Excluded searches
class="someclass1 i-svg i-svg--xs someclass2"
class="someclass1 i-svg someclass2 i-svg--xs"
class="i-svg i-svg--xs"
class="i-svg i-svg--xs someclass1"
class="someclass1 i-svg i-svg--xs someclass2"
Included searches
class="someclass1 i-svg someclass2"
class="someclass1 i-svg"
class="i-svg someclass1"
class="i-svg"
What regular expression can I use for this search?

the problem is that i-svg is a prefix of the string not allowed
You can do it in a 2 step find
Prepare a file with the following 2 regex strings
class="[^"]*i-svg[^"]*"
^((?!i-svg--(xs|sm)).)*$
Second regex based on SO answer
select the first regex: class="[^"]*i-svg[^"]*"
go to the file where you want to find
search for class="[^"]*i-svg[^"]*"
press Alt+Enter to select all matches and put focus in editor
go to other file and pick up: ^((?!i-svg--(xs|sm)).)*$ with Ctrl+C
go back to the file where you want to find
in find dialog press button: Find in Selection
replace regex with: ^((?!i-svg--(xs|sm)).)*$ with a Ctrl+V
Now only the class attributes with only i-svg are found.

Related

Can find match with regex

Hi I'm trying to find line start with "CGK / WIII" but just can find the the first line?
What's wrong with my text? (it is rendered from a pdf file)
Mytext
I am coding with Python to extract data from pdf invoice to dataframe with invoice2data package, and face an error with one text rendered from one pdf file.
First I tried with regex: \w{3}\s\/[\s\w{4}]* and found out that it just can find 1 line.
Then I also tried with fix text "CGK / WIII" should found 4 match. But it's NOT.
I think there are font differences in my text but not sure.
When I turn on global - Don't return after the first match in your linked example, it shows 4 matches.
Also you can not use quantifiers {4} inside a character set (inside []).
I'd do it like this:
\w{3}\s/\s\w{4}

How to replace a pattern in notepad++

I have a sql procedure code. We are migrating the code on different schema. I need to replace all the dimension tables schema.
Example:
Old schemas: DBO.ABC_DIM, DBO.XYZ_DIM
After replace: MART.ABC_DIM, MART.XYZ_DIM
Could any one let me know how we can do this using regex replace.
Thanks
Sky
You must use:
in the "Find what" field:
(DBO)\.
and in the "Replace with" field:
MART\.
Don't forget to place the cursor at beginning of the file. Otherwise the replacements begin after actually cursor position
EDITED:
So in this case if you have others, you can use that:
Find field:
\b(DBO\.)(.+?)_DIM\b
Replace field:
MART\.$2_DIM
Some like:
DBO.ABC_DIM, DBO.XYZ_DIM,
DBO.ABC_DTL, DBO.ABC_2_BCD
become:
MART.ABC_DIM, MART.XYZ_DIM,
DBO.ABC_DTL, DBO.ABC_2_BCD
LAST EDIT:
The above fail with:
DBO.ABC_DIM, DBO.XYZ_DIM,
DBO.ABC_DTL, DBO.ABC_2_BCD, DBO.ABC_DIM, DBO.XYZ_DIM,
DBO.ABC_DTL, DBO.ABC_2_BCD,
DBO.ABC_DIM, DBO.XYZ_DIM,
Because in the second row match DBO.ABC_DTL, DBO.ABC_2_BCD, DBO.ABC_DIM
And DBO.ABC_DTL become MART.ABC_DTL
So the right solution is:
Find field:
(DBO\.)(.[^\.]+?)_DIM
Replace field:
MART\.$2_DIM
see matching results here: http://refiddle.com/refiddles/596b348175622d74ff020000
if you open that schema in VIM, do press esc and then
:s%/DBO/MART
and press enter
:s (colon and s) for substitute
/DBO find DBO
/MART replace it with MART
once you verify that all the DBOs are replace with MART, you need to save the changes by esc and :wq

Notepad++ : Search for static value and replace it with value from list

1 File:
<DisplayName>**just_an_example**</DisplayName>
<DisplayName>**just_an_example**</DisplayName>
<DisplayName>**just_an_example**</DisplayName>
<DisplayName>**just_an_example**</DisplayName>
2 File
**example1**
**example2**
**example3**
**example4**
What do I need:
In notepad++ native search/replace dialog, search for "just_an_example" and replace it with the values from 2nd file, in sequence.
Output:
<DisplayName>**example1**</DisplayName>
<DisplayName>**example2**</DisplayName>
<DisplayName>**example3**</DisplayName>
<DisplayName>**example4**</DisplayName>
Is this possible, to search in all active files under Notepad++. Possible not using Python Script?
Your question implies that the content of file 1 is not relevant (except for the DisplayName tags).
So replace the content of file 1 by pasting all of file 2 and replace new lines by the tags. You can do that in Notepad++ by searching for \n and replacing it by </DisplayName>\n<DisplayName>. All that is left then is manually fixing the first and last line.

Notepad++ replace slashes with spaces between <Tags>1/2/3</Tags> Regex

I have 1500+ xml files and need to change the content between a specific set of <tags></tags>
My file currently looks like this (all squished)
<actor>Natalie Portman/Zooey Deschanel/James Franco/Danny McBride</actor>
I want it to look like this (spaced apart)
<actor>Natalie Portman / Zooey Deschanel / James Franco / Danny McBride</actor>
My search and replace efforts below
Find What: `<actor>(.*)/(.*)</actor>`
Replace with: <actor>(\1 \/ \2)</actor>
My result only separates the last slash
<actor>Natalie Portman/Zooey Deschanel/James Franco / Danny McBride</actor>
using a global search and replace of all slashes is not suitable as the xml file contain many slashes in the form of tag open/closes, xml declarations and general urls containg slashes;
see example below:
<genre>Action</genre>
<director>David Gordon Green</director>
<trailer>http://www.youtube.com/watch?v=FplWxtPzWY8</trailer>
</details>
Possible in SynWrite app.
Make macro which replaces 1 tag content with anything
Run this macro "until end of file"
To make macro,
start macro-record
call Find, regex <t>.+?<, opt "from caret"
call Replace, opt "in selection", from / to anything
stop record
goto dialog "Macros - Customize macros" and u see this
here command "Find dialog" in unneeded, delete it from macro, and macro OK.

Notepad++: Multiple line search & multiple line replace

I'm having a battle with a regex. (MOBI creation)
I have two files: one with XML, the other an HTML table of contents.
The important parts of the XML:
<navPoint id="_NeedsHTMLid" playOrder="40">
<navLabel><text>Needs anchor text from link.)</text></navLabel>
...
The HTML TOC, of course, looks like:
schema.org Article Mark-up
======
Hours and hours... worked with Textpad forever. Saw remarks here, now I'm using NotePad++... some of the regex results are different (NOT that I had it working anyway.) #_[\b(\w\b] was returning the ID: now? Not so much!
Does anyone know how to yank both the ID and the anchor text out of these? I'd be so grateful.
You can use this to get the id and the anchor text at the same time:
_(\w+)\b|([a-Z\s.]+[)]+)
#_[\b(\w\b] is not a valid regex. Try _([^"]+)\b.
Edited: try [^"] in place of \w.
If you want to match the ids and the text, go to Search > Find menu (shortcut CTRL+F) and do the following:
Find what:
id="([a-zA-Z0-9\-\:\_\.]+)"|<text>(.+?)<\/text>
Select radio button "Regular Expression"
Then press Find All in Current Document
You can test it with your example at regex101.
Here's a StackOverflow post about valid id names.
I didn't provided you with a Search and Replace solution, since you didn't mentioned anything about a replacement.