3

I'm dealing with a huge amount of CSS across several files and trying to debug issues with layout looking for bugs like width:105%

I only have access to notepad++ on a Windows machine that supports Regular Expression in Search.

arttronics
  • 9,957
  • 2
  • 26
  • 62
zadubz
  • 1,281
  • 2
  • 21
  • 36

5 Answers5

5
([1-9]0[1-9]|[1-9]{2}\d|[2-9]\d{2}|\d{4,})\s*%

Should do the trick for all numbers in the range of 101 and upward.

101%
110%
210%
999 %
1000000000%

Will all match.

Mahmoud Al-Qudsi
  • 28,357
  • 12
  • 85
  • 125
  • 1
    **+1** Nice! Not to sure about notepad++ syntax: `[^-]width: *([1-9]0[1-9]|[1-9]{2}\d|[2-9]\d{2}|\d{4,})\s*%` Reference [**Online gethifi Tester Screenshot**](http://imgur.com/N6yjO) – arttronics Jul 08 '12 at 22:44
  • 1
    Better: `([^-]width: *(?:[1-9]0[1-9]|[1-9]{2}\d|[2-9]\d{2}|\d{4,}\s)*%)` – arttronics Jul 08 '12 at 22:58
  • @Grundizer, glad to help make this answer better. I like using several Online Regex testers but [**gethifi**](http://www.gethifi.com/tools/regex) has it's moments. Cheers! – arttronics Jul 10 '12 at 11:29
2

Assuming they are all non-negative integer percentages and not zero-prefixed, you could negate anything with 0% to 100% - but only run that over lines with a % in them.

e.g. on the command line

fgrep % something.css | egrep -v ":\s*[0-9]{1,2}%" | fgrep -v 100%

The regular expression will match 0-99%, so I just remove 100% on it's own.

Jay
  • 3,285
  • 1
  • 20
  • 19
  • I'm not familiar with ergep, but standard regex would make me think `[0-100]` wouldn't work as intended... I hope I'm wrong? – Brad Christie Jul 08 '12 at 22:08
  • Absolutely right. I've corrected it. At the cost of a simpler regex, one more pipe. – Jay Jul 08 '12 at 22:13
0
1(?:0[1-9]|[1-9]\d)%

Would be my guess. That matches 10* (where * > 0) or 1** where * > 10

EDIT

For a better method to handle > 100 numbers (and not limit at 999):

(?:\d{4,}|[1-9]0[1-9]|[1-9][1-9]\d|[2-9]\d{2})
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • You could change `1(` to `[1-9](` – Brad Christie Jul 08 '12 at 22:05
  • True, just hope there are no 1000%'s in there too, I guess. – Jay Jul 08 '12 at 22:06
  • @Jay: Honestly, I'd avoid regex like the plague on this and use a parser. However, it's not my project and answering the question at face value. – Brad Christie Jul 08 '12 at 22:06
  • Sorry - I don't want it to look like I'm attacking you but you'd write a full parser just to search through some local files for percentages greater than 100? Also my point is the question needs more than 100 entirely, not more than 100 with only 3 digits - that's all I meant. – Jay Jul 08 '12 at 22:08
  • Jay: No worries, I don't take it personally. Feedback is always welcomed on my posts; But, with that said, I just think regex is over-used and people jump to it too soon sometimes. It has a purpose, but not in 90% of the questions on here. – Brad Christie Jul 08 '12 at 22:11
  • I completely agree, questions that should be phrased "I need a way to parse this" are written "I need a regex for this" when they shouldn't be. I was just taking it from my point of view that if I wanted to do this *quickly*, the quick/dirty disposable command I wrote would do it. – Jay Jul 08 '12 at 22:15
0
[1-9]0*\d{2,}%

Should work for any number >= 100.

TimK
  • 4,635
  • 2
  • 27
  • 27
0

I suppose regex for finding values bigger than 100% percent would be :

width\s?:\s?[0-9]*[1-9]{1}[0-9]{1}[0-9]{1}%

This should find everything even 190999%

RandomWhiteTrash
  • 3,974
  • 5
  • 29
  • 42