|
I am trying to create a formula in Data Studio using RegEx that extracts the channel from the below URLs, all channels are passed as the first value before the first _
ppcnonbrand_sports_uk_google_ourwebsite_b5g5_onlinebetting
crm_sports_uk_email_ourwebsite_b5g5_welcomeemail4b_signin_0_0_0
crm_sports_uk_email_ourwebsite_superboost_221206crmuksportstuenewsletterb_bethere_221206_rnd_0
socialbrand_sports_uk_facebook_ourwebsite_none_carouselawareness_23852435274560534_23852435274610534_0_Facebook_Desktop_Feed_23852435274780534
so from the above i want to return:
ppcnonbrand
crm
socialbrand
I have tried the following but it only returns "null" for everything .. i'm all out of ideas, can anyone suggest something?
REGEXP_EXTRACT(Session Campaign, "^[^_]*")
|
|
|
|
|
I found a solution that worked:
REGEXP_EXTRACT(Session campaign, "^([^_]+)")
|
|
|
|
|
I own few virtual pinball files that I need to be clean up.
I was planning to use RegEx in Excel to clean them out, I'm ok with VBA programming
I know what RegxEx is and what it can do but I'm not familiar on how to write them
Can you help me with those ?
Here is an example of the files and the suggested RegEx "\(.*\).*(?=\[0-9a-zA-Z\.]+\.vpx)":
F:\vPinball\VisualPinball\Tables\Cross Town (Gottlieb 1966).vpx
F:\vPinball\VisualPinball\Tables\Wild Fyre (Stern 1978) 1.1.vpx
F:\vPinball\VisualPinball\Tables\Pirates of the Caribbean Siggis Mod 1.0.vpx
F:\vPinball\VisualPinball\Tables\Punk wip 12.vpx
F:\vPinball\VisualPinball\Tables\Attack from Mars (Bally1995) g5k 1.1.vpx
F:\vPinball\VisualPinball\Tables\Flying Chariots (Gottlieb 1963).vpx
F:\vPinball\VisualPinball\Tables\Lady Luck (Bally 1986) 1.1.vpx
F:\vPinball\VisualPinball\Tables\Fathom (Bally 1981) 1.1a.vpx
F:\vPinball\VisualPinball\Tables\Conan (Rowamet 1983) v1.1a.vpx
F:\vPinball\VisualPinball\Tables\Black Knight - Sword Of Rage.vpx
F:\vPinball\VisualPinball\Tables\Heat Wave (Williams 1964).vpx
F:\vPinball\VisualPinball\Tables\Full (Recreativos Franco 1977).vpx
Ideally the expected name will be Back To The Future.vpx by example
Someone did suggested me this RegEx mentionned earlier, which did most of the cleaning but after running the VBA there a still few that weren't cleaned
Here are those:
Back To The Future 1.4 PF Mod.png
Back To The Future 1.4 PF Mod_thumb.png
Back To The Future 1.4 PF Mod_thumb_sm.png
Back to the Future 1.05 .png
Back to the Future 1.06 .png
Back to the Future 1.14.png
Back to the Future 1.15.png
back to the future 2 mf.png
back to the future mf.png
Back To The Future Starlion MoD.png
Back To The Future Starlion MoD_thumb.png
Back To The Future Starlion MoD_thumb_sm.png
Ideally I was looking for Back To The Future.png
Can you help me please ?
Thanks
|
|
|
|
|
The reason they are left behind is because your Regex only includes filenames that contain the text ".vpx" - which your .png files don't, so can't be matched or removed.
Do two things:
1) Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
2) Learn how regexes work: Regular Expression Tutorial - Learn How to Use Regular Expressions[^]
I'm not going to suggest a regex at all - I have no idea what else is in the folder(s) or how you collected them and no way to find that out - a "random" regex" would be likely to delete a lot more than you actually wanted with no way to test it before you used it!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This works without the $ but I need it to work from the end of the line not the start of the line.
Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)
Not Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)$
What I'm trying to do is grab the street type from an address which works fine using just
[a-zA-z]+$ When the address is like "123 Easy Street" but it doesn't work well when there's a street direction afterwards like "123 Easy Street N". I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not, but it's also not always "Street" as it could be avenue, crescent, drive, highway, road, etc. I think my line above will do what I need but I can't get it to work with the $ to read backwards. Any help would be appreciated!
|
|
|
|
|
Couple of questions. What regex flavor are you using POSIX, PCRE, .NET, Java, etc?
Is this part of a compiled/interpreted program (e.g C++, C#, python), or is it part of something more like a shell script?
Keep Calm and Carry On
|
|
|
|
|
I'm trying to use it within Pabbly Connect, which is an integration system like Zapier or Make. I can use the following spreadsheet type formulas found here https://www.pabbly.com/spreadsheet-formulas/ and similar usually to Google sheet formulas.
|
|
|
|
|
Andrew St. Hilaire wrote:
it doesn't work well when there's a street direction afterwards like "123 Easy Street N"
Your pattern explicitly requires at least two letters at the end of the line, with a non-word character before them. "123 Easy Street N" only has one letter at the end of the line, and is therefore not a match for your pattern.
NB: Your pattern could be simplified to:
(\b[A-Za-z]{2,})$
You need to consider the data you are trying to match, and come up with a pattern to match it. Given your example, you could try:
(\b[A-Za-z]{2,}\b)(\s+[A-Za-z])?$ which would match "Street" in both "123 Easy Street" and "123 Easy Street N".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Andrew St. Hilaire wrote: I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not,
So match the following so it returns 'Main' in the match for any of the following
1. 123 Main
2. 123 Main View
3. 123 Main N
4. 123 Main View S
(\b[A-Za-z]+)((\s+[A-Za-z])?)$
First clause matches the street.
Second clause optionally matches a single last character.
Why the extra parens in the second clause? Because I prefer to always have a match for optionals. So in this case first match is street name and second match (always there) is either something like 'S' or it is empty/null. If the parens were not there then there might or might not be a second match (you would need to test for it.)
|
|
|
|
|
Hello everyone!
since more than two decades programming with VC++ I never used Regular Expressions.
But now I need... The solution in VS2022 contains some thousands line looking like:
some_object.MyMethod(comma_separated_parameter_list, &SomeClass(argument)optiolal_parameter-list)
What I need is removing the ampersand (&) from these code expressions.
I found a way to search for such an expression. It is something like something like
.*MyMethod\(.*, &SomeClass\(
But I could not find a working expression for Replace.
So I need your help guys!
|
|
|
|
|
Typically, one would use capture grops and replacement expressions. In your case you might do
(.*MyMethod(.*, )&(SomeClass()/s\1\2
If there are many SomeClasses that you would like to replace, you might be able to use
(.*MyMethod(.*, )&(\w*()/s\1\2 Be cautious! I Have not tested either of these, and any time you're experimenting with regular expression replacements, Bad Things can happen. Back up Early! Back up Often!
This all assumes that you actually want to make replacements using Visual Studio, more information for which can be found here:
Keep Calm and Carry On
|
|
|
|
|
Thank you for pointing me out to capture groUps! Very interesting.
However your suggestion with Quote: (.MyMethod(., )&(SomeClass()/s\1\2 doesn't work.
Example:
Quote: original line:
qwerty.MyMethod(param1, param2, &SomeClass(param3), param4);
search for the parttern
.*MyMethod\(.*, &SomeClass\( finds the substring of the origin up to
SomeClass(
But trying to replace it (to remove the &) using your suggestion results to
(.MyMethod(., )&(SomeClass()/s\1\2param3), param4);

|
|
|
|
|
Visual Studio's "Replace in Files" option (Ctl-Shift-H) allows you to use regular expressions, for both the find and the replace parts, and even offers a drop down of selections for the more common situations.
|
|
|
|
|
Thank you Richard.
I know about these options in Visual Studio.
What I don't know is how to remove an & from a code line that I already found (using regular expressions) but leave all the other texts before and after this & unchanged!
|
|
|
|
|
I just tried a quick test and this works:
Expression in the Find box: &([a-z][A-Za-z]*)
Expression in the Replace box: $1
The find expression looks for the ampersand followed by a lowercase letter, followed by zero or more alphabetics, and captures everything apart from the ampersand, which is outside the parentheses.
The replace expression says to replace everything that was found (including the ampersand), with the text in the capture group, which is the portion in parentheses.
You will most likely need to modify the find portion to match your exact requirements.
|
|
|
|
|
Thank you Richard!
|
|
|
|
|
Thank you both Richard and k5054!
The hint to look at "capture groups" was very useful!
I've just tested: so find
(.*MyMethod\(.*, )&(SomeClass\(.*)
and replace with
$1$2 gives me what I need: the ampersand has been removed! 
|
|
|
|
|
Hello,
I need to write a regular expression search which will locate when a line ends with the same text as the preceding line, but does not have the same first 10 characters. So in this example:
[11:12:21] Hello this is Tom. How are you?
[11:14:08] Hello this is Tom. How are you?
. . . I would need to search for consecutive lines for which the text was the same after the time entered in brackets.
I know that this search:
FIND: ^.{11}(.*)$
REPLACE; $1
. . . will locate the first 11 characters and remove them.
This search:
FIND: ^((.{10}).*)(?:\r?\n\2.*)+
REPLACE: $1
. . . will locate lines where the first 10 characters are the same and remove them.
But I can't figure out how to structure the search so it checks the text from position 11 to the end of the line, and then checks if the text on the next line from the 11th character to the end of the line is the same.
|
|
|
|
|
You cannot do what you are asking with a regular expression.
(There is in fact a very wrong way to attempt this which is ridiculous and would lead to nothing but a maintenance nightmare.)
However in a programming language that uses regexes the algorithm that you would create would look like the following
1. Read a line
2. Parse the line to remove the timestamp.
3. Does it match the previous one? (Do whatever you want)
4. Otherwise save it for the next time
5. Go back to step 1 until there are no more lines to read.
|
|
|
|
|
-Hardsoul -housejazz
+Jean Michel Rotin
-Anita Perras
-St.Niccolo
+Mahalia -fr
to
Hardsoul -housejazz
Jean Michel Rotin
Anita Perras
St.Niccolo
Mahalia -fr
|
|
|
|
|
The regex to match a single character at the start of the line using regex for the major languages.
^[-+]
To match more than one.
^[-+]+
Replacing it is a different problem and it specifically depends on the programming language you are using and which you did not specify.
|
|
|
|
|
My campaigns all follow the same naming convention, i am trying to use a Regex_Extract formula in DataStudio to create a new custom dimension that only displays the 4th last element in the below campaign: "ctatext"
Each element is separated by a _
channel_product_country_medium_brand_offer_campaignname_ctatext_date_objective_0
Closest i have gotten is:
REGEXP_EXTRACT(Session campaign, '(.+){4}(?:[^_]+.)')
but that only returns the 4th character in the string .. can anyone help ?
|
|
|
|
|
How about something like:
_([^_]+)(_[^_]*){3}$ regex101: build, test, and debug regex[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh yes that has helped, thank you very much!
|
|
|
|
|
Hi,
I want to split the text above in three results.
Every result starts with the word "Leistung" and can optionally have a second line starting with "Zusatz".
My regex-expression ist currently this:
/Leistung [ ]*[\w\d äöüÄÖÜ]*\n[\w\d äöüÄÖÜ\*]*/gm
But this does not fit exactly.
This ist the text:
Leistung Armeotraining ET Anzahl 1
Zusatz *TextZusatz_Anf1*
Leistung Atemtherapie 30 Anzahl 2
Leistung Aktivierungsgruppe Anzahl 3
Zusatz *TextZusatz_Anf3*
The result should be:
Leistung Armeotraining ET Anzahl 1
Zusatz *TextZusatz_Anf1*
Leistung Atemtherapie 30 Anzahl 2
Leistung Aktivierungsgruppe Anzahl 3
Zusatz *TextZusatz_Anf3*
Can anyone help me with the regex-expression?
Thank you in advance!
Tobias
|
|
|
|