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 7 years ago.
Improve this question
I am struggling with what is most probably a very simple regular expression.
Consider this the text I wish to evaluate:
??Company=My Company Name Ltd??Address= 29 Acacia Road, Nuttytown, AA1 9AA??Description=A very rambling description here... goes on for a bit and then somemore??E-mail=bert#bertswork.com??Version=Super Plus??Expiration date=01/01/2026??First name=Bert??Last name=Bloggs??
I want to extract the string for My Company Name Ltd that is between the Company= and the ??Address= tags.
Please can some kind soul put me out of my misery!
You can try this
/(?<=\?{2}Company=)(.*?)(?=\?{2})/
I used lookbehind (?<=) and look ahead (?=) so that ??Company= and ?? is not included in the match.
Regex
Although we usually want to see what you've tried, I've been in your situation - A complete noob and not knowing even where to start, so hope this helps...
Since you know each tag starts with a ?, you can use the following:
\?\?Company\=([^?]*)
This basically says:
It starts with ??Company=
Take all the characters after that until you find the next ? character and place them in a capture group.
Hope that does the trick
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 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 5 years ago.
Improve this question
I used this regex if($tmp =~ /(wot.*)\b/) ($tmp refers to the data mentioned below) to match just the path \wot\maks\xxx\xxxx\xxx\xxxxxxxxx\xxxxxxxxx .06.55Z but i don't get the next line using the regex i mentioned above, i am able to get just \wot\maks\xxx\xxxx\xxx\xxxxxxxxx\xxxxxxxxx how can i get the whole path
\wot\maks\xxx\xxxx\xxx\xxxxxxxxx\xxxxxxxxx
.06.55Z
06/15/2017 09:06 PM 111 ja.xml
1 File(s) 211 bytes
Change the regex to if($tmp =~ /(wot.*\n.*)\b/)
/(wot.*)\s\S+\b/ worked for me.
Have you tried testing solutions on a regex testing site? I find it handy when trying to tune regex.
I like http://regexr.com/ for testing.
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
How can I find all the strings which is ended with .xml
I try with new RegExp("^\.xml") which is not working any idea?
^ means at the start of the string. $ is the opposite of it. You would need
var rgx = /\.xml$/gm
Note that I've included m flag, since I think that text might span many lines. If that's not the case, remove the m from the regex.
It depends in which format you have your files (if each file name on a separate line or it's just a text and so on).
Assume that file name consist of letters, dots and dash signs I would try this pattern: [A_Za-z\-\.]+\.xml
Or if you want to find only file names, without extension, use this one: [A_Za-z\-\.]+(?=.xml)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any regex master that can help me?
I have a list of words like {first|second|third}, and I want just the last word, in this case {first|second|third}.
Can anyone help me please??
Edit:
After feedback I am adding more information.
I have a sentence such as "I am going to France {today|tomorrow|next week}" for example. But I want only "I am going to France next week".
I tried (?<=\{).*?(?=\|.*?\}) but this gives me |tomorrow|next week, I just want next week without the vertical lines.
PS it doesn't necessarily have to 3 words, I just want the last regardless.
The regex you need is obviously:
((\w|\s)+)\}
A python test of the regex:
>>> import re
>>> test = """ds like {first|second|third}, and I want just t"""
>>> re.findall('\|([^\|]+)\}', test)
['third']
To generally replace {a|bc|def} with def with no nesting or other complications, search for the regex
\{[}]+\|([^|}]+)\}
and substitute with the first (and only) parenthesized subgroup. In Perl, that would be something like
s/\{[}]+\|([^|}]+)\}/$1/g;
Many other languages have a similar syntax, though it might be less compact. In PHP, look for preg_replace.
The expression looks complex, but isn't really; we look for a literal { followed by the longest possible string of characters which are not }, as long as it's followed by a literal | and (subgroup) a string of characters which are neither | nor }, and finally, after the subgroup, a literal }.
Try this
/\{.+?([^|]+?)\}/
(you can easily test it by typing the following in your browser's JS console)
"{first|second|third}".replace( /\{.+?([^|]+?)\}/, "$1")
or even
"I am going on the {first|second|third}".replace(/\{.+?([^|]+?)\}/, "$1")
-> "I am going on the third"
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.