This question already has an answer here:
Regex match strings between asterisks
(1 answer)
Closed 2 years ago.
Is it possible to do a RegEx to only match the last asterisk right before and first asterisk right after an value?
Value: **example**
My actual regex: /\*(.*?)\*/g
My actual regex matches the two asterisks before and after word example, but i want to do a regex that only matches the last asterisk right before and the first asterisk right after the word.
Thank you!
try /[*][^*]+[*]/gm
Works as tested on regex101.com
Related
This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Closed 2 years ago.
Hey I have a list of files
B123245.xml
B123245-ext.xml
1234W01.xml
1234W01-ext.xml
Now I need a regular expression filter only the files without -ext in the name.
I tried already this ^.+(?!-ext)\.xml$
but it is not working.
What am I doing wrong?
Not sure about your exact needs, but if you want to exclude those file where "-ext" is right before the xml extension I think you could use:
^.+(?<!-ext)\.xml$
See the demo
^ - Start string anchor.
.+ - 1+ character apart from newline.
(?<!-ext) - A negative lookbehind to assert position isn't preceded by "-ext".
\.xml - Match a literal dot and "xml".
$ - End string anchor.
With the help of user 'The fourth bird' I found out the correct structure.
Here is the correct result
^(?!.*-ext).+\.xml$
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
Good morning,
Could tou please help on this regular expression request.
I would like all characters before "-", but only if that chain has a lenght of 7 characters
If 5QHTN33-48314742, result 5QHTN33. But if AAA5QHTN33-48314742, then no result.
Thanks for your help.
as '^' refers to start of line and '$' refers to end of line, I highly prefer to say you have to split the line with spaces(regex of split: (\s+) , for java: (\\s+)) so you can use below regex after splitting and use it on every element, hope to be helpful:
(^)((?<word>[\w\W]{7})\-.+)($)
Explanation
(?<word>[\w\W]{7}) will capture your word into a group with name word ,so you can get it easier.
This question already has answers here:
Regex: matching up to the first occurrence of a character
(14 answers)
Closed 4 years ago.
can someone please quickly help me with regularexpression to match any character and group it which is coming behind front shash:
ae-app001/UK/Server/company
in this i want to match ae-app001 only.
the format remains the same except that we dont know how many slash might be there,
sometimes the string might be just :
ae-app001/UK/Server
so i need a generic regex which will match string1 in the below:
string1/string2/string3/string4
string1/string2/string3
etc..
/^([^\/]+)/ Demo
But what if there's no slashes? Is it ok to capture whole string?
This question already has an answer here:
Parse IP addresses from txt
(1 answer)
Closed 7 years ago.
>>> pat=re.compile('^\d{3}-\d{2}-\d{4}$')
>>> pat.findall('my sssn is 111-22-3333')
I am trying to catch ssn in the text. I tried the expression in pythex and it worked there but it's not wokring in python. I am new to this.
Remove the ^ and the $ anchors:
Your regex should be:
\d{3}-\d{2}-\d{4}
The caret ^ matches the position before the first character in the string, and since you have m in your input, \d{3} doesn't match.
$ matches after the last character in the string, you don't really need it here unless you want nothing to appear after the last four digits.
pat=re.compile('^.*?(\d{3}-\d{2}-\d{4}).*$')
Just group what you want and use .* to catch the buffer.This will make ^$match the whole string as opposed to what you were doing as then there were character after and before what you wanted.
This question already has answers here:
Difference between regex [A-z] and [a-zA-Z]
(6 answers)
Closed 8 years ago.
I'm struggling with the following regexp
[A-z0-9]+
If tested against this string:
||a919238[.--a]asd|
it returns a919238[, including the square bracket.. I tried to input my test case on regex101 to understand what's wrong, but the site regex explanation is not helping, probably I'm not able to see my mistake.
Why is the square bracket included in the result?
Because
[A-z0-9]+
↑ ↑
is from A to z, see the ASCII table, ] appears between the two characters:
A===>64
z===>122
[===>91
So it is in between the range you have defined.Use [A-Za-z0-9]+
You can use /[a-z0-9]+/i (the i makes it case-insensitive), or /[A-Za-z0-9]+/.