Match a word from a link [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to work with regex but I'm still not capable of. Asking for your help!
I have links like these:
https://open.spotify.com/track/1Q07lxRM6aQJYtRFzQUtwu?si=LrEcPs3pSxaznY2GLH4V8Q
https://open.spotify.com/album/7lyxArCeA4kkHRiYpnh8eA
open.spotify.com/artist/1mBlZPMpRL8wT9aHBnBBph
I'd like to match the "artist" part in the last link. How can I do it? I thought about using slashes as "separator" than get the string from there but I have no idea.

Assuming you want to extract the top directory name following the
domain name, how about:
import re
url = 'open.spotify.com/artist/1mBlZPMpRL8wT9aHBnBBph'
m = re.search(r'(?:https?://)?[^/]+/([^/]+)', url, re.IGNORECASE)
if m:
print(m.group(1))
Output:
artist

Below, I'm using Python.
It's just build a case insensitive regex that advance any chars (.) with +(1 or more chars) and than use a prefix that occurs always before artist link artist/, finally use ()s to group. Inside ()s uses a class for letters and digits with + suffix (1 or more chars)
.+artist/([a-z1-9]+)
The replaced string it just
/1
The details vary a little bit according to the programming language adopted
See here:

Related

Akeneo attribute regex wir OR "|" not working [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
The problem in Akeneo seems to be that simple regex combinations not working. I think the functionality (a single or group regex combination) is not integrated/implemented proper in Akeneo. If there is anybody out there who knows a trick to do a regex combination please let me know.
Tried to figure out how to make regex with | OR working in Akeneo "attributes".
the simple Example not working either a syntax error or no matching in Akeneo:
find this "323"
or find "123456"
\d{3}|\d{6}
Can anybody help?
According to the documentation, you need to use regex literal notation, and anchor the match both at the start and end of the string (so, add a grouping):
/^(\d{6}|\d{3})$/
Here, / are regex delimiters, ^ matches the start of string, (...) is a capturing group that contains two alternatives, six digits or three digits, and then end of string anchor, $, follows.

Regex to identify 2 characters in the correct position from a 4 character string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
For example, I have the String "abcd", and I want all matches to be found in which at least 2 of those characters match, in the correct position. So, ab12, a1c2, 12cd, etc will all match because they contain at least 2 characters in the correct index from abcd.
I realize I could try doing it by /ab..|a.c.|a..d|.bc.|.b.d|..cd/g, but is there a better/simpler way to do this?
Thank you!!
You can easily accomplish this with the PyPi regex package.
See code working here
import regex
s = 'abcd'
a = ['ab12', 'a1c2', '12cd', '123d', 'abc4', 'abcd']
r = regex.compile('(?:'+regex.escape(s)+'){e<=2}')
for x in a:
if(r.fullmatch(x)):
print(x)
This uses fuzzy matching {e<=2} to identify strings that have 2 or fewer errors (insertion, substitution, deletion). You can instead specify {s<=2} for only substitutions if you'd like.
For list comprehension, you can replace the last three lines with the following:
print([x for x in a if(r.fullmatch(x))])

Filter out exact portion of string that contains special characters bash [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I’m trying to write a command in bash (on Mac OS 10.12) to filter out a portion of a string that contains special characters:
The portion of the string to be removed is:
,MYDOMAIN\sct_DesktopAdmin
An example of what I want is:
Initial string:
domain admins,enterprise admins,MYDOMAIN\sct_DesktopAdmin,MYDOMAIN\sct_LocalAdmins
Final string after filtering:
domain admins,enterprise admins,MYDOMAIN\sct_LocalAdmins
Because the initial string will vary from machine to machine it is important that the filter is an exact match to this portion only.
I’ve been trying to create something with sed but have so far only produces filters that remove all the special characters and my attempts at escaping the individual special characters have not worked.
Any help would be much appreciated.
You can use substring replacement (replacing MYDOMAIN\sct_DesktopAdmin, with an empty string):
str="domain admins,enterprise admins,MYDOMAIN\sct_DesktopAdmin, MYDOMAIN\sct_LocalAdmins"
printf "${str/MYDOMAIN\\sct_DesktopAdmin, }\n"
Edit: remove second / thanks to Toby Speight, use printf instead of echo, add space at the end to conform to OP edit

how to check in python, that a string contains only alphabets and hypen [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to filter medical words from general english words.
but most of the drugs name contains hypen in it.
pls suggest how to check in python, that a string contains only alphabets and hypen.
for example : anti-allergic
Simplest way to check string is as below, remove '-' from string and check if remaining characters are all alphabets.
test_str = 'anti-allergic'
if test_str.replace('-','').isalpha():
print('Valid string')
This can be accomplished by using regular expressions (https://docs.python.org/3/library/re.html), where a (very quick and dirty) regex could ask for all letters, a to z (and A to Z), that has a hyphen in it.
([a-zA-Z]+[-].+)
Would match the following:
suoad
ADDADA
waeewrw
omaeqweSADADSwu
iraaief
anti-allergic
ANTI-ALLERGIC
testtesttest
You can test this out yourself using https://pythex.org/.

Regular expression for negativenumbers (123.456,789-) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm searching for a pattern for matching numbers with hyphen at the end like this :
125,000-
1.234,567-
60,000-
Just try with following regex:
/\d[.,\d]*-/
Or even:
/\d([.,]?\d+)*-/
NOTE Aleš Krajník's answer is basically the same as the answer I finally came to, except that his uses non-capturing grouping (as captures are not required)... he should get the votes IMHO as he was first
Note that in the following answer I'm assuming that , comma is the decimal separator, and that the . point is the thousands separator (eg for European numbering).
I believe the following is "correct":
^\d{1,3}(.\d{3})*(,\d+)?-$
This matches eg:
1-
12-
123-
123.456-
123.456.789-
1,0-
1,01-
1,001-
1,0001-
123.456,01-
123.456.789,0001-
etc
But will not match eg
1234-
123,-
123.4-
123.1,001-
123.45-
1..1..1-
1.1.1-
1,1,1-
.,-
etc.
The exact regex should read: \d{1,3}(?:\.\d{3})*(?:,\d+)?-
Try something like this:
[0-9.,]+-
\d{1,3}(?:[,]\d{3})*- takes internationalisation into account. The one below allows strings like 1..9 to match, which really should not.