Pedro Vagner

Productivity Tips

a year ago
ProductivityRegular Expression (regex)

Explanation of the most commonly used regular expressions.

<tag>[\s\S]*?</tag> Select between tag. Exclamation mark matches the fewest possible characters (makes the quantifier non-greedy).

def.{0,23}?bar Select def followed by bar on the same line and don't exceed 23 characters between. Exclamation mark matches the fewest possible characters (makes the quantifier non-greedy).

def[\s\S]{0,23}?bar Select def followed by bar on multiple lines and don't exceed 23 characters between. Exclamation mark matches the fewest possible characters (makes the quantifier non-greedy).

("|')expression("|') Match expression between quotes or double quotes.

(_name|_inherit).*\.equipment' Search for _name or _inherit followed by .equipment' on the same line.

^((?!_name|_inherit).)*\.equipment'.* Match lines that contains .equipment', except those preceded by _name or _inherit on the same line.

^((?!bar|foo).)*$ Match lines that doesn't contains bar or foo.

expression(?!s) Match expression not followed by the character s.

Match attribute in XML: myAttr=\"([^"]*)\"

Match variable edges: filter_domain_\w+_write

References

Regular Expression Reference: Special Groups