SomeRandomText=%EXAMPLE1%,MoreRandomText=%%ONE%%!!%%TWO%%,YetMoreRandomText=%%THREE%%%FOUR%!!%FIVE%\%%SIX%%
I'm in need of a regular expression which can pull out anything which is wrapped in '%%'- so this regular expression would match only the following:
%%ONE%%
%%TWO%%
%%THREE%%
%%SIX%%
I've tried lots of different methods, and am sure there is a way to achieve this- but i'm struggeling as of yet. I mainly end up getting it where it will match everything from the first %% to the last %% in the string- which is not what i want. i think i need something like forward lookups, but struggling to implement
You need a non-greedy match, using the ? modifier:
%%.*?%%
See it working online: rubular
This can also be done be restricting what is allowed between the %s.
%%[^%]*%%
This is more widely supported than non-greedy matching, however
note that this won't match %%A%B%%. Although, if necessary, this can be done with some modifications:
%%([^%]|%[^%])*%%
Or equivalently
%%(%?[^%])*%%
Related
I have the following regex in jersey, that works:
/artist_{artistUID: [1-9][0-9]*}
however, if i do
/{artistUID: [artist_][1-9][0-9]*}
it does not, what i do not understand how the regexes are being build and do not find any good documentation for it. What i want to do is something like this:
/{artistUID: ([uartist_]|[artist_])[1-9][0-9]*}
to recognize terms like "artist_123" and "uartist_123" and store them in the artistUID value.
You can use the alternation group ((...|...)) rather than a characrter class [...] (that matches 1 single character defined inside it).
Use
/{artistUID: (uartist|artist)_[1-9][0-9]*}
Or to make it shorter, use a ? quantifier after u to make it optional:
/{artistUID: u?artist_[1-9][0-9]*}
See the regex demo
My college asked my to provide him with a regex that only matches if the test-string endswith
.rar or .part1.rar or part01.rar or part001.rar (and so on).
Should match:
foo.part1.rar
xyz.part01.rar
archive.rar
part3_is_the_best.rar
Should not match:
foo.r61
bar.part03.rar
test.sfv
I immediately came up with the regex \.(part0*1\.)?rar$. But this does match for bar.part03.rar.
Next I tried to add a negative look behind assertion: .*(?<!part\d*)\.(part\0*1\.)?rar$ That didn't work either, because look around assertions need to be fixed width.
Then I tried using a regex-conditional. But that didn't work either.
So my question: Can this even be solved by using pure regex?
An answer should either contain a link to regex101.com providing a working solution, or explain why it can't work by using pure regex.
You could use lookahead to verify the one case that fails your original regex (.rar with .part part that isn't 0*1) is discredited:
^(?!.*\.part0*[^1]\.rar$).*\.(part0*1\.)?rar$
See it in action
This is an old question, but here's another approach:
(?:\.part0*1\.rar|^(?<!\.)\w+\.rar)$
The idea is to match either:
A string that ends with .part0*1.rar (ie foo.part01.rar, foo.part1.rar, bar.part001.rar), OR
A string that ends with .rar and doesn't contain any other dots (.) before that.
Works on all your test cases, plus your extra foo.part19.rar.
https://regex101.com/r/EyHhmo/2
I am working with regular expressions, I need to create an expression for validating strings against the following scenario:
Solution.<word1|word2|word3>.<word4|word5>.anyword.(any word containing proj in it)
I tried
Solution.\b(word1|word2|word3)\b.\b(word4|word5)\b.(.*).\b(.*proj)\b
But this allows strings like Solution.word1.word4.blabla.blabla.csproj, meaning it allows anything before the proj because of the .*.
Can someone help me with this??
Looks like you need this regex:
Solution\.(word1|word2|word3)\.(word4|word5)\.([^.]+)\..*?\bproj\b
RegEx Demo
You might want to try (need to escape the . and allow capturing group to have chars except .):
Solution\.\b(word1|word2|word3)\b\.\b(word4|word5)\b\.([^\.]*)\.\b([^\.]*proj)\b
It's hard to consider the actual strings you want to allow without more clarification.
You can try the following regular expression.
Solution\.word[123]\.word[45]\.\w+\.\w*proj\b
I have tried many combination of
\d{1,2}:\d{2}
to validate a period of time(ie: 0:33 or 12:33).
Therefore, for the most part the above expression works, but I also need to
1) validate ":33" and
2) invalidate "00:33a"
I have googled around and try to combine \s* but it still does not satisfy both conditions.
Any help is appreciated.
If you want to match only valid times (e.g. 23:59, but not 25:03 etc), you could try the following regular expression:
^([01]?[0-9]|2[0-3]):[0-5]?[0-9]$
I believe you just need to specify the beginning ^ and end $ string signifiers
^\d{1,2}:\d{2}$
That way 00:33a will invalidate
Looking at your question more closely and expanding on Gijs's answer, this may be what you're after...
^(?:[0-9]?|(?:[0-1][0-9])?|(?:2[0-3])?):[0-5][0-9]$
Allows for ':mm', 'h:mm' or 'hh:mm'.
I'm not sure how universal the (?: non-capturing group is - I'm accustomed to it from .Net.
I need to match a substring in php substring is like
<table class="tdicerik" id="dgVeriler"
I wrote a regular expression to it like <table\s*\sid=\"dgVeriler\" but it didnot work where is my problem ?
You forgot a dot:
<table\s.*\sid="dgVeriler"
would have worked.
<table\s+.*?\s+id="dgVeriler"
would have been better (making the repetition lazy, matching as little as possible).
<table\s+[^>]*?\s+id="dgVeriler"
would have been better still (making sure that we don't accidentally match outside of the <table>tag).
And not trying to parse HTML with regular expressions, using a parser instead, would probably have been best.
I dont know what you want get but try this:
<table\s*.*id=\"dgVeriler\"