Skip to content

Instantly share code, notes, and snippets.

@dellermann
Last active December 18, 2015 16:39
Show Gist options
  • Save dellermann/5812937 to your computer and use it in GitHub Desktop.
Save dellermann/5812937 to your computer and use it in GitHub Desktop.
Various regular expressions for developers.

Constraints simplification

Remove parentheses from constraints such as number(blank: false) to number blank: false:

  • Search: (\w+)\(([^)]+)\)$
  • Replace: \1 \2

Method call simplification

Replace all method calls of the form foo('bar', 5) to foo 'bar', 5:

  • Search: ^([ \t]*[\w.]+)\(([^])]+)\)$
  • Replace: \1 \2

In Vim use this command: :%s/\(\w\+\)(\([^])]\+\))$/\1 \2/gc.

It doesn't replace occurrences such as foo([1, 2, 5]) because the replacement foo [1, 2, 5] would be interpreted as property access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment