Solved

Trim multiple alphabet words from a string (Query)

  • 8 June 2023
  • 5 replies
  • 110 views

Badge +1

Hi! I’m trying to get only alphabet words from query string.

I used extract regular expression,

(a)  it includes ‘%20’ (a space on html) 

or 

(b) it only gives me the first word.

 

What expression should I use to get all alphabet words?

 

(a)

 

(b)

 

icon

Best answer by danielle 12 June 2023, 16:23

View original

5 replies

Userlevel 3
Badge +1

Hi @Matilda - This is a great question! If the only thing you’ll need to remove from the query string is the URL encoded space, then instead of extracting directly from the query property, we can nest another formula that replaces the %20 with a space in the query string before we extract the values:

Additionally, I noticed that these might be search strings. One other thing that might be beneficial is setting a top-level formula to convert the strings to lowercase. This would allow you to combine any similar search strings with different casing. Don’t hesitate to let me know if you have any lingering questions!

Badge +1

Hi Danielle, thank you for a quick response!

I could replace %20  and convert to lower case successfully 🙏 

 

While, our mobile site is using different url format.

Could you advise how to get only ‘white dress’ from below url example?

other parts than ‘white dress’ are constant for all search results

https://mobile.fashiongo.net/#/search/result;searchQuery=white%20dress?pageTitle=Search&searchQuery=white%20dress&cid=0&orderBy=rel&success=true

 

Appreciate your help!

Badge

Hi @Matilda

Based on your question "While, our mobile site is using a different URL format. Could you advise how to get only 'white dress' from the below URL example? Other parts than 'white dress' are constant for all search results," here's the answer:

To extract only the term "white dress" from the provided URL while ignoring the constant parts for all search results, you can follow these steps:

  1. Remove any URL encoding: Replace "%20" with a space character (" ") to decode the URL encoding.
  2. Extract the value of the "searchQuery" parameter: Look for the "searchQuery" parameter in the URL and retrieve its value.

Here's an example of how you can extract the "white dress" term:
 

By following these steps, you can successfully extract the term "white dress" from the provided URL.

Hope this helps!

Badge +1

Hi @Alabs I Shubham Singh

I tried your solution, changed the property type to hash from query.

Kind of getting likable results, but I also want to make all results in lower case.

Seems like there is a limit of adding conditionals.

 

Let me know if you come up with any idea!

 

Thank you

Badge

Hi @Matilda 

To extract and lowercase the search query from the provided URL, follow these steps:

  1. Convert to lowercase: Apply the "Convert to lowercase" formula to the entire search query.
  2. Extract the value of the "searchQuery" parameter: Look for the "searchQuery" parameter within the query part of the URL and retrieve its value.
  3. Remove any URL encoding: Replace "%20" with a space character (" ") to decode the URL encoding.

For your reference, I have created a dummy property and you can see the result, all in lowercase.

 

 


In your case, follow the same criteria and sequence and replace the red highlighted area in the image with searchQuery=([A-Za-z0-9 ]+)
This pattern matches the text "searchQuery=" followed by any combination of uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and spaces. By capturing the matched group, you can retrieve the search term from the query property.

Additionally, to utilize this property you can create a pageview event where the hash contains /search/result. By leveraging this event in your analysis, you can easily group and categorize the data by using this property.

I hope this detailed explanation helps. Let me know if there's anything else I can help you with!

Reply