Oracle regex string not beginning with '40821' - regex

I am trying to define a regex that matches string with numbers and it's not begining with 40821, so '40822433598347597' matches and '408211' not. So, I've tried
^(?!40821)\d+
Works perfectly in my regex editor, but still doesnt work in oracle. I know, it's very easy to use where not but my goal is to do it using only regex. Please, some pieces of advice, what am I doing somthing wrong?

According to this question, negative lookahead and lookbehind are not supported in Oracle.
One way would be to explicitly enumerate the possibilities using alternation. In your case it would be something like:
^([012356789]|4[123456789]|40[012345679]|408[013456789]|4082[023456789])

I think you try to use negative lookbehind:
(?<!a)b matches a "b" that is not preceded by an "a"
Source: http://www.regular-expressions.info/lookaround.html
That kind of Perl's sytax is not supported by Oracle.

Related

How to use lookahead in regex to match a word that only appear in certain context?

I'm learning regular expression and now I'm on chapter of lookahead. In the class example, if you want to match "sea" only in "seashore", you do:
/(?=seashore)sea/
or
/sea(?=shore)/
But what if I want to match "shore" only in "seashore"? I tried:
/(?=seashore)shore/
and
/(?=sea)shore/
but none of them work. Did I misunderstand something? As far as I understand, lookahead is like a premise for matching a string. But why I cannot match a "shore" only in context of "seashore"? Anyone can give me a hit? Lots of thanks!
FYI: this is the regex pal I'm using to test my regular expression:http://www.regextester.com/
You should use lookbehind if it is supported by your regex engine. Like so:
/(?<=sea)shore/
Otherwise (e.g. in Javascript, where lookbehinds are not supported), you'll have to match the whole thing and use capturing groups to separate the part that you want from the rest.
If you write /(?=seashore)... it already expects the sea... ahead and so, if it would match, it would match from there. There is no way to just exclude that thing from the match if you use lookahead.

Regular expressions, negative lookahead anywhere in the string

Im sorry if this is asked and has an answer but I can't find it.
I know about regex lookarounds and negative lookahead.
Thing is that negative lookahead examines what comes right after current position in a string.
What I need is to find and discard matches if string contains words like "career(s)" and "specials" for example, but if it contains them anywhere in the string.
What would be the efficient way of doing that?
At the moment I'm using PCRE flavor but the more general regex is, the better.
Thank you.
You can use this regex:
^(?!.*(?:career\(s\)|specials)).*
Or if s is optional then use:
^(?!.*(?:career|special)s?).*
RegEx Demo

How to use ? with a string in RegEx?

Basically I want to check the following
www should not be in a string, however this obviously doesn't work as in the following regex any character is basically separated by a |. So w|w|w..
[^www]?
How can I solve this problem? Is there any easy possibility?
You don't need the optional operator ? here. You can use a Negative Lookahead assertion.
^(?!.*www).*$
[^www] is the same as [^w].
Using negative look-around can help you achieving that:
^((?!www).)*$
The above regex matches everything that doesn't contain www.
Use a negative lookahead:
^((?!www).)*$

Extract number + letter combination from string

I'm intrested in extracting c8127c6ea6a44c109b5e35ce61cd4b0096a9c6dc from a string that looks like this:
?t=c8127c6ea6a44c109b5e35ce61cd4b0096a9c6dc'
Here is my attempt at capturing the result in to a group.
?t=([a-e]\d+)'
Could anyone point me in the right direction, since this obviously isn't working?
http://regexr.com?383s6
You wanna put the \d in the [a-e] block and escape the ?:
\?t=([a-f\d]+)'
(and I assume you're looking for hexadecimal so it should be a-f?)
You can use this regex:
\?t=([a-e0-9]+)'
OR usig negation:
\?t=([^']+)'
In Ruby language you can try Rubular tool online to test your regular expressions.
\?t=(\w+)'
should do the match.

Help with regex

I got the following regex:
"throw new [a-zA-Z]+Exception"
I want do modify it so that all Argument exceptions ("Argument[a-zA-Z]*Exception") are not included
How do I combine them?
Take a look at this page for more information: http://www.regular-expressions.info/completelines.html
Keep in mind that different regex implementations may not support all of the options available, so YMMV. If you have a regex designer tool that will let you test the expression live, I highly recommend it. You need a negative lookahead expression:
"((?!Argument)[a-zA-Z])*Exception"
Make sure your regex library supports lookahead and negative lookahead expressions.
You need a negative lookbehind. See here for more details. Perl-specific but your particular implementation likely has something similar.
Lookbehind has the same effect, but
works backwards. It tells the regex
engine to temporarily step backwards
in the string, to check if the text
inside the lookbehind can be matched
there. (?<!a)b matches a "b" that is
not preceded by an "a"