0

I want to replace all first "/" with "[" but all second "/" with "]". GoogleDocs offers a regular expression search-and-replace, but I have no clue how to use that for this "first and second" issue. Example of source and target below.

What do I have to enter in the Search and Replace fields of GoogleDocs dialogue?

current state

p pen /pen/
b bad /bæd/
t tea /tiː/

intended solution

p pen [pen]
b bad [bæd]
t tea [tiː]
6
  • take advantage of the space before the first slash. replace <space>/ with [ and then / with ]. You shouldn't need regex here. Commented Mar 7, 2019 at 14:26
  • Google Docs Find and Replace does not support replacement backreferences, it is not clear how to do that without them. Try /\b to replace the first and \b/ to replace the second slash. Commented Mar 7, 2019 at 14:29
  • It's a very long table. Unfortunenately, in many cases there is a tab #9 and not a #32 in front of the slash. But yes, a nice idea as work-around. However, I hoped to learn to to use regular expressions with "first" and "second" occurences here and how to keep whatever is in-between. Commented Mar 7, 2019 at 14:30
  • With normal regex, it is trivial, not Google Docs. Commented Mar 7, 2019 at 14:31
  • Thanks for the "trivial" solution. So GoogleDocs cannot do this? How do they intend this feature to be used? Commented Mar 7, 2019 at 14:43

1 Answer 1

2

In Google Sheets you can use capture groups so you could do something like Find: /(.*)/ Replace with: [$1]

Docs does not support this functionality so you may have to move your stuff around a little.

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

1 Comment

Thanks. Indeed it works in Google Sheets. The answer of Wiktor solved the replacement issue.

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.