1

I need a regex that can get the company name (in this case "google.com") from this format: company=google.com&extension

According to https://regex101.com/ this should work: (?<=company).*(?=&ext)

However when I try =REGEXEXTRACT(B3, "(?<=company).*(?=&ext)") in Google Sheets I get an error:

Function REGEXEXTRACT parameter 2 value "(?<=company).*(?=&ext)" is not a valid regular expression.

Ive also tried =REGEXEXTRACT(B3, "/(?<=company).*(?=&ext)/")

Function REGEXEXTRACT parameter 2 value "/(?<=company).*(?=&ext)/" is not a valid regular expression.

4 Answers 4

1

The REGEXEXTRACT function does not support lookarounds so you have to use non-capturing groups for parts that should not be captured and captured groups.

Just use (?:company)(.*)(?:&ext) instead of yours. Also, you were using , after B3. Do not know which version of Google Sheets you are using but it did not work for me and I had to change it to ;

=REGEXEXTRACT(B3; "(?:company)(.*)(?:&ext)")

NOTE: If you're using non-capturing groups then do not forget to use capturing group, otherwise it will return the whole matched values including non-capturing ones as well.

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

2 Comments

After I hit enter the ; gets replaced by a , and I also get this error: Error Function REGEXEXTRACT parameter 2 value "(?:company)(.*)(?:&ext)" does not match text of Function REGEXEXTRACT parameter 1 value
When I was using , it suggested replacing it with ;. I think it is just a version depending issue.
1

You could as well try the following:

=REGEXEXTRACT(B3,"=(\S*)?&")

This should extract only the specific string google.com or any word between the = sign and the & characters.

1 Comment

I had to change it to "=(\S*)?&e" and then it worked.
1

You can match company and capture the part before the ampersand in a group:

company=([^\s&]+)&ext

See a regex demo.

enter image description here

Comments

0

One can also use the following

=REGEXEXTRACT(B2,"=(.*)&")

enter image description here

1 Comment

I have to use "=(.*)&e" but then it worked

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.