0

I noticed that VS Code has the ability to search using regex; however, I'm wondering if there's an easier way to replace all of the symbol assignments in my code with strings. For example:

  • :variable would convert to 'variable'
  • variable: would convert to 'variable' =>

Alternatively, I've tried to put together a bash script that would do this, but it seems that my matches are going beyond where it should stop. For example:

grep -RE "\[\:.*?\]" .

seems to be a good match, but if the line has more than one ], then it goes to the end. For example, this entire area gets matched:

[:test_recipient] : opts[:recipient:]

as opposed to

[:test_recipient]

and

[:recipient]

individually. How can I only grab up to the end of the first closing bracket?

1 Answer 1

1

You can use a negated character class to exclude matching the square brackets

For example

echo "[:test_recipient] : opts[:recipient:]" | grep -Eo "\[:[^][]*]"

Output

[:test_recipient]
[:recipient:]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.