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 have data as follows:
text = "hello there, a:123ijk^&45b: I am working on this regex a:45o#iu67b: I need to solve it"
I want to get only the string sequences between a: and b: . My output should be
position('a:123ijk^&45b:') and position('a:45o#iu67b:') . I tried a few regex patterns but it returns between first a: and last b:, so couldn't solve it. As an alternate I have a boring way of writing a loop based solution but want to avoid it.
Appreciate if anyone can can help with this
Use a lazy quantifier:
a:(.*?)b:
"I want to get only the string sequences between a: and b: "
Maybe like:
(?<=a:).+?(?=b:)
The ? in the middle makes the greedy + lazy and stops the match when :b is ahead the first time. This would now get the values that are actually in between
Edit:
"realized ... my question was also put wrong.. what if I want to include only a not b?"
Try this:
(?<=\s)a:.+?(?=b:)
I included an extra positive lookbehind to make sure the a: is preceded by a \s.
Related
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.
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))])
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 looking for regex extract that would pull what I need from the following strings please:
2/A 100 House
to result in : 2/A 100
7/X 7 Capital Flat
to result in : 7/X 7
0/H 98 Kale Road
to result in : 0/H 98
The numbers and letter after the / can be anything so needing something more generic. I'm not too familiar with regex and I've only managed to extract everything before first occurrence of a letter using (.*?)\[A-Za-z]
I need to keep the first occurence of a letter and the following space and number but want rid of every other letter after that.
I'm coding in SQL.
Thanks for any help you can give!
Looking at your example, I'm assuming both the first character and the last one before the text you want to remove will be a digits. And the first character after / will be a letter
\d+\/\w+\s+\d+
See demo: https://regex101.com/r/cLGvkm/1
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 4 years ago.
Improve this question
I am interested in finding combinations of 2 words that appear in the same sentence.
For example:
Looking for "hello" & "There" that are in the same sentence.
My name is Danny. Hello. I am there. whats up ? <-- NO MATCH
My name is Danny. Hello there. whats up ? <-- MATCH
The rule is simple - I dont want a dot character (.) top appear between the 2 words.
You might want to try this:
\b(H|h)ello\b[^.]+\b(T|t)here\b
It matches Hello There, Hello there, or hello there, depending on the case.
Demo is here.
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.