Why won't this regexp work in google spreadsheets? - regex

I'm trying to extract from a url using a regexp in google spreadsheets. However the spreadsheet returns #VALUE! with the following error: Invalid regular expression: invalid perl operator: (?<
Here is the regexp I'm using: (?<=raid_boss=)[a-zA-Z0-9_]+
A sample url will contain a variable in it that says raid_boss=name. This regexp should extract name. It works in my testing program, but not in google spreadsheet.
Here is the exact contents of the cell in google spreadsheets: =REGEXEXTRACT( B1 ; "/(?<=raid_boss=)[-a-zA-{}-9_]+" )
Any insight or help would be much appreciated, thank you!

Sounds like whatever regular-expression engine Google Docs is using doesn't support lookbehind assertions. They are a relatively rare feature.
But if you use captures, REGEXEXTRACT will return the captured text, so you can do it that way:
=REGEXEXTRACT( B1 ; "raid_boss=([a-zA-Z0-9_]+)" )

Javascript is not the issue - Google Sheets uses RE2 which lacks lookbehind
along with other useful things.
You could use:
regexextract(B1, ".*raid_boss=(.*)")
or else native sheet functions like FIND, SUBSTITUTE if that isn't working
Finding a good regex testing tool is tricky - for example you can make something that works in http://rubular.com/ but fails in GSheets. You need to make sure your tool supports the RE2 flavour eg: https://regoio.herokuapp.com/

Related

Google Analytics Regex - Matching Specific Words, but Not Others

I don't usually use Regex. I'm working on Google Analytics Goals and I want to create a step in the funnel that will match URLs containing /resource/ and the word ebook or report, but do not include thank or thanks.
It would match:
/resource/example-ebook-request
/resource/research-report-2018/
It would not match:
/resource/example-ebook-request/thank-you/
/resource/research-report-2018/thanks/
/some-other-ebook-no-resource-subfolder/
I'm having a hard time getting the combination of this correct in a way that will work for Google Analytics since it doesn't support look behind. Any suggestions?
Try Regex: \/resource\/[^\/]*(?:ebook|report)[^\/]*\/?$
Demo

online tool available to validate regex in firestore?

There are tools available to validate the regex used in javascript / prolong etc but i am writing rules in google-cloud-firestore. I want some tool to check my regex.
please suggest.
If you read my original answer. Ignore it.
You can use the matches comparison.
matches
Performs a regular expression match, returns true if the whole
string matches the given regular expression. Uses Google RE2 syntax.
The full list of string validation rules available for Cloud Firestore are shown here.

Regular expression not working in google analytics

Im trying to build a regular expression to capture URLs which contain a certain parameter 7136D38A-AA70-434E-A705-0F5C6D072A3B
Ive set up a simple regex to capture a URL with anything before and anything after this parameter (just just all URLs which contain this parameter). Ive tested this on an online checker: http://scriptular.com/ and seems to work fine. However google analytics is saying this is invalid when i try to use it. Any idea what is causing this?
Url will be in the format
/home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd
so i just want to capture URLs that contain that specific "z" parameter.
regex
^.+(?=7136D38A-AA70-434E-A705-0F5C6D072A3B).+$
You just need
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B.+$
Or (a bit safer):
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&.+$)
And I think you can even use
=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&)
See demo
Your regex is invalid because GA regex flavor does not support look-arounds (and you have a (?=...) positive look-ahead in yours).
Here is a good GA regex cheatsheet.
To match /home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd you can use:
\S*7136D38A-AA70-434E-A705-0F5C6D072A3B\S*

Filtering Google Analytics API with Regex - Stop Before a Character (query string)

I'm working with Google Analytics API add-on for Google Spreadsheets to pull in data.
I know basic regex and it turns out that negative lookbacks / not operators (I'm assuming they're the same?) aren't allowed in Google Analytics, therefore I'm having difficulty with this filter.
I want to filter out all URL page paths that have a query string in them. Here's a sample list:
/product/9779/this-is-a-product
/product/27193/this-is-a-product-with-a-query-string?productId=50334&ps=True
/product/281727/this-is-another-product-with-a-really-long-title
/product/979
/product/979/product-12-pump-septic
/product/9790/the-1983-ford-sedan
/product/9791/remington-870-3-express-410-pump-shotgun
/category/2738/this-is-a-category
I want my output to be:
/product/9779/this-is-a-product
/product/281727/this-is-another-product-with-a-really-long-title
/product/979/product-12-pump-septic
/product/9790/the-1983-ford-sedan
/product/9791/remington-870-3-express-410-pump-shotgun
This is the start of my Regex...
ga:pagePath=~^/product/(.*)/
...which ignores the fourth line but I have no idea what to put after the second backslash.
I've tried a few things here (like this one Regular expression to stop at first match) and have been testing my code here (http://www.analyticsmarket.com/freetools/regex-tester).
Any insight would be greatly appreciated!
You can use the following regular expression to match the desired output.
^/product/.*/[\w-]+$
Live Demo
Try this also. It will strictly capture. what you need.
^\/product\/((?:(?!\/|[a-z]).)*)\/[\w-]+$
SEE DEMO : http://regex101.com/r/gS3lF8/2
^/product/\d+/[a-zA-Z0-9-]+$
You can try this.See demo.
http://regex101.com/r/oE6jJ1/16

Regex for string plus number range

I'm using a regular expression to extract data from our reporting tool.
Here is the range:
cid=300000[195-429]
I tried ?cid=[300000195]-[300000429]
But they are not working.
cid is part of the string. So, for example, return ?cid=300000197 and return ?cid=300000300
And everything in between.
What would be the correct regex syntax?
Try this:
cid=30000(19[5-9]|[2-3]\d{2}|4[0-2]\d)
Paste the regex here and give it a try.
Google Analytics' regular expression engine is rather weak compared to those used by Perl, PHP, JavaScript, and so on, so this took some tweaking. But as long as you're sure your URLs will be following the expected format, this should get the job done.