How do I turn Bay 13 | Brand PS/CPP into 13 using REGEXREPLACE in Google Sheets?
I can't figure out how to NOT include a pattern, as it seems whatever I type as the pattern it takes it out completely. I'm not used to this behavior in REGEX.
For instance:
REGEXREPLACE("(?i)bay ", )
returns 13 | Brand PS/CPP.
I want to keep the 13 (which could be any number between 1-35 including halves (12.5)), and get rid of everything after it including the "|" pipe.
try "everything after bay and before a pipe":
=REGEXEXTRACT(A1, "(?i)bay (.+) \|")
or if you want specifics:
=REGEXEXTRACT(A1, "(?i)bay (\d+(?:\.\d+)?) \|")
I think you want to use REGEXEXTRACT here rather than REGEXREPLACE:
REGEXEXTRACT("\d+(?:\.\d+)?", "Bay 13 | Brand PS/CPP")
Related
In the default letters that I see and use, the address of the from address is as following:
Max Mustermann, Beispielweg 23 a, 12345 Köln
I would like to change the separation symbol (in the above example ",") to "|".
So it will look like:
Max Mustermann | Beispielweg 23 a | 12345 Köln
I based my question on the text in example
Using
\setkomavar{backaddressseparator}{~|~}
solved my problem
I need to find all the records which contains the given sub-string(art), and the condition is the given substring is either a complete word within the string or the start of any word within the string.
Sample data. Program
id | name
-----------
10 | Report of Quarter 1
11 | The Art Program
12 | The Artificial Program
From the above data, I must be able to get the record numbers 11 and 12 but not 10.
I am trying like this
Program.where("name ~* ?",'art\b')
but it's not working
I have also tried with
Program.where("regexp_match(name, ?)",'/art\b/i')
this too is not working
any help is really appreciable. Thanks!
EDITED
I guess you are using Postgres since you gave an example with regexp_match
Try Program.where("name ~* ?",'\mart') :)
You can see hidden in the Postgres docs ("Regular Expression Escapes" section) that \b means "backspace, as in C" whereas \m "matches only at the beginning of a word"
An example url that I'm trying to collect the values from has this pattern:
https://int.soccerway.com/matches/2021/08/18/canada/canadian-championship/hfx-wanderers/blainville/3576866/
The searched value always starts at the seventh / and ends at the ninth /:
/canada/canadian-championship/
The method I know how to do is using LEFT + FIND and RIGHT + FIND, but it is very archaic, I believe there is a better method for this need.
Another alternative:
="/"&textjoin("/", 1, query(split(A1, "/"), "Select Col7, Col8"))&"/"
The searched value always starts at the seventh / and ends at the ninth /:
Here's another way you can do it:
="/"®exextract(A1,"(?:.*?/){7}(.*?/.*?/)")
You can use =REGEXTRACT() to match part of the string with a regular expression:
For example, If A1 = https://int.soccerway.com/matches/2021/08/18/canada/canadian-championship/hfx-wanderers/blainville/3576866/ ,
then
=REGEXEXTRACT(A1, "\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*(\/[^\/]*\/[^\/]*\/)")
returns
/canada/canadian-championship/
Explanation: \/ is '/' escaped. [^\/]* matches any non '/' character 0 or more times. \/[^\/]* is repeated 6 times. () captures a specific part of the string as a group to be returned. Finally (\/[^\/]*\/[^\/]*\/) matches the essential part we want.
Little bit different approach.
=REGEXEXTRACT(SUBSTITUTE(SUBSTITUTE(A1,"/","|",9),"/","|",7),"\|(.*?)\|")
I know how to split text using other delimiters such as a comma, equal sign etc. I am having trouble for examples that require a number delimiter.
A typical split formula that uses a comma delimiter would look like this:
=SPLIT(A1, ",")
I am struggling with splitting text that looks something like this. The delimiter here is a number.
This is a random text of 20 characters but could be 30 characters as well.
Output should be
This is a random text of | 20 | characters but could be | 30 | characters as well.
Please help. Thanks
Try the following:
=SPLIT(REGEXREPLACE(A1,"\d+","|$0|"),"|")
Maybe better, to remove spaces:
=SPLIT(REGEXREPLACE(A1,"\s*(\d+)\s*","|$1|"),"|")
I'm not quite good in regex.
With my input string LT 1 BLK 4 LAKES OF PARKWAY 5 R/P & AMEND
I'd like to match just the only part between the figure 4 and 5 in the string.
meaning that, my expected result is LAKES OF PARKWAY.
I've tried to come up with a pattern to get such result.
\d+\s+([A-z ]+)(\d+.*?)*$
but with my pattern, it only matches BLK and 5 R/P & AMEND, as group #1 and group #2 respectively. At the end of my thought pattern, I decide to use end of string matching, $.
So, when 5 R/P & AMEND got matched, the pointer should move further behind to the sub sequence part. Then, ([A-z ]+) should match LAKES OF PARKWAY.
What's wrong with my pattern? and how to get it to work?
Any advice would be very much appreciated.
Try \d+\s+(\D+)\d+\D*$
\D means 'anything that is not \d, so it won't be allowed to match, for example, between the first 1 and 4, because then the ending of the regex would be rejected at the later 5.