Write a unique regex to match both requirements [duplicate] - sql

This question already has answers here:
How do I make part of a regex match optional?
(2 answers)
Closed 26 days ago.
I have two URLs patterns:
URL Pattern1: https://foo.xyz.com/abc/qyu234
URL Pattern2: https://sptfoo.xyz.com/g0/c/abc/qyuu234
I need to extract abc from each URL.
I have written separate regex to archive the task individually:
URL Pattern1: https://foo.xyz.com/abc/qyu234
Regex: r'.foo..xyz.com/([^/]*)'
URL Pattern2: https://sptfoo.xyz.com/g0/c/abc/qyuu234
Regex: r'.foo..xyz.com/g0/c/([^/]*)'
But I need one single regex that can help me match the requirements in both the patterns.

Regex from below will work for both cases.
r'https://(?:foo|sptfoo).xyz.com/(?:g0/c/)?([^/]*)'

Related

decode this regex [duplicate]

This question already has answers here:
What do comma separated numbers in curly braces at the end of a regex mean?
(6 answers)
Closed 3 years ago.
I've tried to understand the below but don't seem to get the last part of the regular expression which has {1,40}. Overall, I know the pattern tries to match the special characters and something else (the {1,40})
regexp_like(COLUMN,'^['||UNISTR('\0020')||'-'||UNISTR('\0060')||UNISTR('\007B')||UNISTR('\007D')||UNISTR('\007E')||UNISTR('\00C0')||'-'||UNISTR('\00DF')||']'||'{1,40}$')
regexp_like() checks that a string matches the regex provided as second argument.
Your regexp looks like ^[...]{1,40}$.
^ is the beginning of the string and $ is the end, so the entire string must match the regex.
[...] is a character class, that contains a bunch of characters code points. All characters of the string must belong to that list (any other character is forbiden). You would need to to check what they correspond to: unicode.org is your friend. For the first code points:
\0020 space
\0060 grave accent
\007B left curly bracket
finally, {1,40} is a quantifier: the length of the string must be at least one and at most 40.

Search by regular pattern in iOS [duplicate]

This question already has answers here:
What's the regular expression that matches a square bracket?
(10 answers)
Closed 3 years ago.
Trying to search bbcode-style tags with regular expression:
For example, I needed [user=1]John Dow[/user] with regular: [[user=[0-9]+].*?[/user]]
But couldn't receive needed result.
Remove the outer pair of brackets and escape the literal brackets (unlike the range-of-characters brackets)
let pattern = "\\[user=[0-9]+\\].*?\\[/user\\]"

how to get specific part from string in sql

I want to retrieve file names from urls in sql.
for example:
Input:
url:
https://www.google.co.in/root/subdir/file.extension?p1=v1&p2=v2
https://www.abxdhcak.com/sitemap-companies.xml
then Output should be:
file.extension
sitemap-companies.xml
To match your expected output you can use REGEXP_REPLACE
REGEXP_REPLACE(txt, '^.*/|\?.*$') as rg
This does 2 things:
'^.*/'
This removes all characters up to and including the last forward-slash in the string.
'\?.*$'
This removes all characters after and including a question mark.
This may not work for all cases, but it works for the examples provided.

How find substring with regular expression [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a sting "some text #texttext some other text #texttagtext". I need get all words with '#' symbol. If there are some ## or more symbols together, I need to replace them with one symbol '#'. Could any one help me with regular expression ? Thanks in advance.
Regex:
(?<=^|\s)#+(?=\S+)
Replacement string:
#
In objective-c, you need to escape backslash one more time.
DEMO
To find all the words that starts with #
(?<=^|\s)#\S+
\S+ would match any non-space character one or more times.
OR
(?<=^|\s)#\w+
\w+ Match any word character one or more times.
To find all the words that starts with one or more #
(?<=^|\s)#+\S+

VB.NET function for uppercasing the first letter of each word [duplicate]

This question already has answers here:
How to uppercase the first character of each word using a regex in VB.NET?
(9 answers)
Closed 8 years ago.
I'm looking for do this in VB.NET,
hy how are you
to,
Hy How Are You
Anyone have any idea?
This following will do what you want without using regex (and is more readable than a regex solution):
Dim s As String = "some sentence that i want to capitalise"
Debug.WriteLine(Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s))
Output:
Some Sentence That I Want To Capitalise
And you can also do this (from the Microsoft.VisualBasic Namespace):
Debug.WriteLine(StrConv(s, VbStrConv.ProperCase))
You can do that using regular expressions. There are a useful class named Regex that will help you a lot. Please follow this link for more information.