2

My objective

This question is about Visual Studio Code search box.

I want to replace all the "spaces" by the character "_" inside the my substring with spaces of mystring

for example:

-> From

{
    "Show_details": mystring("my substring with spaces"),
    "Type_of_event": mystring("my substring with spaces2"),
}

-> To

{
    "Show_details": mystring("my_substring_with_spaces"),
    "Type_of_event": mystring("my_substring_with_spaces2"),
}

What I tried

I only managed to get the `my_substring_with_spaces`. But I do not understand how to proceed further.
Search: mystring\("([a-z]*?( )[a-z]*?)"\)

1 Answer 1

3

You can use

(?<=mystring\("[^"]*)\s+(?=[^"]*"\))

Details

  • (?<=mystring\("[^"]*) - immediately to the left, there must be mystring(" and then 0 or more chars other than "
  • \s+ - one or more whitespaces (remove + if two consecutive spaces must be converted to two consecutive _s)
  • (?=[^"]*"\)) - immediately to the right, there must be 0 or more chars other than " and then ").

See the screenshot:

enter image description here

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

3 Comments

regex killer 😆
In the Edit->Find in Files it shows the error Regex parse error: Lookbehind assertion is not fixed length. Any idea ?
@micaball Yes, do not use this regex in Find in files, it uses a different regex flavor.

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.