How do I find everything beside regex in notepad++? - regex

I want to find and mark all the code that doesn't fit my regex.
[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*
Basically I want to mark everything beside red-highlighted part
my-regex-at-work.jpg
The code:
.pull-right>.dropdown-menu {
right: 0;
left: auto
}
.dropup .caret,
.navbar-fixed-bottom .dropdown .caret {
content: "";
border-top: 0;
border-bottom: 4px dashed;
border-bottom: 4px solid\9
}
.dropup .dropdown-menu,
.navbar-fixed-bottom .dropdown .dropdown-menu {
top: auto;
margin-bottom: 2px
bottom: 100%;
}
#media (min-width:768px) {
.navbar-right .dropdown-menu {
right: 0;
left: auto
}
.navbar-right .dropdown-menu-left {
right: auto;
left: 0
}
}
.btn-group,
.btn-group-vertical {
position: relative;
display: inline-block;
vertical-align: middle
}
My ideas do not work
[^[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*]
[^[[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*]]

it seems to be not possible with notepad++ because of backtracking, it could be done if regex engine supports control verbs:
[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*(*SKIP)(?!)|.*
regex101
to tell to the engine to skip the matched part and fail, otherwise when engine fails to match it continues with input cursor on next character.

Append \K|.* to your regex:
[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*\K|.*
Then hit Mark All button.

Related

Bug in star rating under product title

I'm seeing this star rating problem on my site:
https://goldenshop.be/product/golds-gym-strength-stringer-goud/
As you can see, the first star seems to have a duplicated half star in the background. How can I remove this bug?
Thanks in advance for the support!
change this in css codes :
.woocommerce .star-rating span {
text-indent: 999px;
left: 0px; <----- 2px to 0px
}
.woocommerce .star-rating span::before
{
text-indent: 0px; <----- -2px to 0px;
}

Notepad++ regex replace Css #media

I want to clean out everything between #media and }. Only after research I still cannot find how. I want to replace everything between the BOLD text below, including the BOLD text itself:
#media all and (max-width: 240px)
{
#toast-container>div
{
padding: 8px 8px 8px 50px;
width: 11em;
}
#toast-container .toast-close-button
{
right: -.2em;
top: -.2em;
};
}
#media (min-width: 768px)
{
.lead
{
font-size: 19.5px;
};
}
RESULT 1: #media }
RESULT 2: nothing
In Replace Dialog(Ctrl+H), enable Regular Expression and . matches newline
Then, search for:
#media.*?\};.*?\}
or
#media.*?(\};)\s*?\}
And replace for empty string... (this will remove all - including bold text)
Let me know if it works.

What RegEx to select comma separated CSS selectors individually in SublimeText?

The other day I had to prefix every single CSS selector with another tag in order to increase its specificity. I though I'd flex my regex muscles a bit and I came up with this regex:
(^(((\s)+)?(?!.+: )(?!\.IE)[a-z.].+?)([,{]))
The plan was to replace the entire captured match with something like 'body $1'. There are a couple of negative lookaheads to avoid matching lines like background-color: property and .IE selectors
The screenshot describes the problem:
Here is some sample text:
/* line 18, ../scss/SplashPage/_page.scss */
* {
-webkit-tap-highlight-color: transparent;
}
/* line 35, ../scss/SplashPage/_page.scss */
body header {
*zoom: 1;
background: #eaeaea;
}
/* line 221, ../scss/MainStyle/_mixins.scss */
body header:before, body header:after {
display: table;
content: "";
}
/* line 224, ../scss/MainStyle/_mixins.scss */
body header:after {
clear: both;
}
body .utility-nav {
right:0
}
/* line 40, ../scss/SplashPage/_page.scss */
body .home-link {
text-indent: -99999px;
white-space: nowrap;
overflow: hidden;
background: transparent url("~/images/clipsal-logo2.png") center center no-repeat;
background-image: -webkit-linear-gradient(transparent, transparent), url("~/images/clipsal-logo.svg");
background-image: linear-gradient(transparent, transparent), url("~/images/clipsal-logo.svg");
background-position: top left;
background-repeat: no-repeat;
display: block;
float: left;
/*width: 120px;
height: 50px;
margin: 20px 0px 15px 25px;*/
background-size: 100% auto;
}
I think it's the start of line anchor (^) that needs do be dropped. Having said that I am not sure what the regex should be :)
Note: I understand that the problem could have easily been solved using SASS, but where's the fun in that!
Thanks

Regular Expression to get "left" only from style

This is my regular expression to get "left" and its value.
/(left\s*:\s*)(\d+)?(px)/
My problem is, it pulls padding-left and left.
vertical-align: top; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: list-item; width: 420px; position: absolute; top: 0px; left: 700px; height: 580px;
How can I get "left" and its value only?
I put a \s in front of left and that works... But I can't always guarantee there will be a space in front of left.
Thanks...
/(?:^|[^-])(left)\s*:\s*(\d+|auto)([a-z]{2})?/
Will fetch what you want with "left" in group 1, "700" in group 2 and "px" in group 3
(?:^|[^-]) = The start of the string, or a non-hyphen character
(left) = The word left (capture group 1)
\s*:\s* = A colon with optional space characters either side
(\d+|auto) = One or more numbers, or the string "auto" (capture group 2)
([a-z]{2})? = Two letters, e.g. "px" "em" "pt" (capture group 3 - optional)
Instead of using a RegEx, you could use a CSS parser. This is a more robust solution as a parser is better suited for this task.
An example using Python and cssutils
example.css
.myClass {
border: 1px solid black;
margin-left: 100px;
left: 700px;
padding-left: 50px;
}
get-left.py
#!/usr/bin/env python
import cssutils
sheet = cssutils.parseFile('example.css')
for rule in sheet:
if rule.type == rule.STYLE_RULE:
for prop in rule.style:
if prop.name == 'left':
print("{0}: {1}".format(prop.name, prop.value))
In this Python script, prop.name will return the name of the property and prop.value its value.
output
$ ./get-left.py
left: 700px

add class to each line of css with regex

I want to add a class at the start of each line of my css
I want
.more {
padding: 5px 10px 0;
}
#fbook {
display: inline;
float: left;
margin: 0 0 0 4px;
width: 320px;
}
to look like
.test .more {
padding: 5px 10px 0;
}
.test #fbook {
display: inline;
float: left;
margin: 0 0 0 4px;
width: 320px;
}
something like this.
^([A-Za-z0-9]+)$
would work if my css looked like this
more
{
padding: 5px 10px 0;
}
fbook
{
display: inline;
float: left;
margin: 0 0 0 4px;
width: 320px;
}
but I can't seem to get anything working when to find the . # {
Try this
$result = preg_replace('/(?i)^([.#a-z]+\{)$/m', '.test $1', $subject);
Explanation
"
(?im) # Match the remainder of the regex with the options: case insensitive (i); ^ and \$ match at line breaks (m)
^ # Assert position at the beginning of a line (at beginning of the string or after a line break character)
( # Match the regular expression below and capture its match into backreference number 1
[.#a-z] # Match a single character present in the list below
# One of the characters “.#”
# A character in the range between “a” and “z”
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\{ # Match the character “{” literally
)
\$ # Assert position at the end of a line (at the end of the string or before a line break character)
"
You can use a modern tool like LESS. Simply take your code, and wrap it with .test{ }:
.test {
.more {
padding: 5px 10px 0;
}
#fbook {
display: inline;
float: left;
margin: 0 0 0 4px;
width: 320px;
}
}
If you only need it one time, you can do it online: http://leafo.net/lessphp/#demo
If you want to do it from time to time, there are less libraries for many languages which you can use, and a client side JavaScript option.