سؤال

I'm trying to find and replace all instances of:

font-size: pem(18)

But the problem is that they all differ in numbers. I'm not a regex expert, i've researched a few ways to do this with no luck as I don't really know what I am looking for to solve this issue.

I know the regex feature exists in Sublime, but when I think of Regex I'm thinking with a javascript or jquery mindset, not pure regex since I'm inexperienced there.

هل كانت مفيدة؟

المحلول

This is simple if you start to learn RegEx:

font-size: pem\(\d+?\)

First, escape all RegEx metacharacters if you're trying to match that exact character. In this case they are "(" and ")". \d+ matches one or more digits, ie. 4, 14, 144, etc. If you wanted to get more advanced and limit your integer value to, say, anything between 1 and 19, you could modify the RegEx to:

font-size: pem\((?:[1-9]|1[0-9])\)

Here, | is a standard "or" operator. \d is simply shorthand for [0-9], but I've used [0-9] here for better readability. (?: ... ) indicates a non-capturing group so that the closing ")" matches the single "1-9" value as well.


Now if you were after changing all integer values you could do a find and replace like so:

Find

(?<=font-size: pem\()(?:[1-9]|1[0-9])(?=\))

Replace

12

Then all pem values between 1 and 19 would become 12.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top