1

How would I replace in PhpStorm (it is not important I guess) all occurrences of (selecting string which starts with {!! and ends with !!}):

{!! $arr['my.key.1234'] !!} to {!! $arr('my.key.1234') !!} (note change in braces)

I tried to select the key with this regex: \{\!\! \$arr\[.*.] !!} which works but how do I now replace it?

EDIT:

I only want to select array key which is variable so my regex doesn't work - it selects whole line.

1
  • @PrestonGuillot it's a function to replace which I do not need (sorry for confusing question) - what I want is to write an expression which allows me to replace square brackets for round brackets. Commented Feb 18, 2020 at 11:44

2 Answers 2

2

In PhpStorm, open the replace dialogue and make sure you've checked the Regex checkbox.

For your find, you can use:

(\{!!\s*\$\w+)\[('[\w\.]+')\](\s*!!\})

This captures the 3 parts you want to keep. You then replace the brackets and use $1, $2 and $3 to insert your original content around the new brackets.

$1($2)$3

Screenshot of how to do this:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

You can search like this with phpstorm:

  • (\{\!\!.+\$.+)(\[) replace by $1(
  • (])(.*\!\!}$) replace by )$2

Don't forget to check the box regex in search toolbar.

2 Comments

When I use first replacement expression - the second expression does not match pattern but that's to be expected.
Strange, for me it works, i use first replacement to put ( and the second replacement to put ) works also.

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.