Regex to match a string only if a string does not exist - regex

Can anyone suggest me a solution in Regular Expression, to match a string if it does not exist in the given string.
Suppose I have a String
Rohan is going to Home
and I don't want that
Going to
string should exist, then it will not return. But if the string does not contain contains "going to", then string will be returned
Valid
Rohan is at Home
Invalid
Rohan is going to Home
I have heard that regex isn't well suited to negate something (except a single character). Regex is more intended to match strings, not "not match" them. Still if someone have solution please suggest in Regular Expresion
I have tried to create a Regular Expression,but didn't get success till now.
SELECT 1
FROM DUAL
WHERE REGEXP_LIKE (' Rohan is 12 home'
, '^\s[^going to])$','i');

Try this, which uses a negative look ahead:
^(?!.*going to.*$)

Check out negative lookaheads.

Related

Regex to strip character

I have another regex question. Sorry.
Givs a way to strip a character in a match group with regex?
Price: 2'765'874.65
Regex: ([\d']+(?:\.\d{2})?|[\d\.]+(?:,\d{2})?)(?![\d\.,])
Output: 2'765'874.65
Needet Output: 2765874.65
That found my price.
But I search a regex ( ot str_replace) that stip ' and show me the Output match group without '
regex:([\d]+(?=\')*(?:\.\d{2})?|[\d\.]+(?:,\d{2})?)(?![\d\.,])
output:2' 765 ' 874.65
This way it would only match the numbers check out.
The only thing I did was to change [\d'] To ([\d]+(?=\')* which I will explain why.
here (?=\') is a lookaround, and its type is a look ahead look around.
anything(?=s.th)====> first it checks whether infront of anything is there something ? if the answer is yes .... it matches the pattern but does not consume that s.th meaning it only needs to check whether it exists or not but does not shows them in the output.
in other words, it says look ahead but does not consume it.
after you got the numbers with grouping them you can get the output.
NOTE: Consider adding which implementation of regex you are using.

Regex expression to match word in a string

I've been banging my head with this issue as I can't get this expression to work.
I'm trying to match and output a specific word from a string, so for example, take this string:
<ANIMALS>
<value>DOG CAT COW</value>
</ANIMALS>
And now I want to match any one of them and return that value otherwise none, let's say, COW.
I've tried a lot of varying expressions with no luck such as:
IF(VALUE == "/(^|\W)COW($|\W)/", "COWVALUE", "NONE")
This doesn't work, nor do any other variants I've tried. If I keep the original string as a single word and no actual calling expression, just a word, then it always works. As soon as I introduce a string of words then I can't make it happen.
Could anyone help please?
Thanks!
Get rid of (^|\W) and ($|\W), since that only matches at word boundaries, but you want to match COW when it's not by itself as a word. The regular expression should just be /COW/, it will match that string wherever it appears in the string.
BTW, to match word boundaries you can use \b rather than those alternations.
Not sure what programming language you're using but following is a simple example based in Javascript to do achieve your goals.
regex demo

re2 does not seem to give correct results for some patterns when compared to pcre

I was trying to use both pcre and re2 and I came up with the following observation.
When I give the string as
"ab cd"
and the pattern as
"^[^c]"
re2 returns NO MATCH but its actually a match.
That is to say when I type this RE2::FullMatch("ab cd", RE2("^[^c]")) I get FAIL/No Match.
Please let me know if I am going wrong somewhere or what is the problem?
RE2::FullMatch matches the entire string, like Jerry says.
There are two basic operators: RE2::FullMatch requires the regexp to
match the entire input text, and RE2::PartialMatch looks for a match
for a substring of the input text, returning the leftmost-longest
match in POSIX mode and the same match that Perl would have chosen in
Perl mode.
https://code.google.com/p/re2/wiki/CplusplusAPI

Regex substring

I'm trying to select a substring using regex and I'm going round in circles. I need to select everything before the first "_".
exampale URL - GI_2013_JUNE_10_VOL3_LASTCHANCE
So the result Im looking for from the URL above would be "GI". The text before the first "_" can vary in length.
Any help would be much apprecited
The regex would be:
^[^_]+
and grab the whole regex match. But as a comment says, using a substring function is more efficient!
^[^_]*
...is the expression you're looking for.
It basically says: Select everything that is not an underscore, starting at the beginning of the string.
http://regexr.com?356in

How can I write a regular expression match for a string that must contain the following characters: thankYou.sjs?donate_page

I need to create a regex query for a Google Analytics goal. The goal url must contain:
thankYou.sjs?donate_page
However, there are many urls than can render this string, all with other modifiers that I don't care about.
Please advise.
#ExplosionPills: I think you forgot about the special meaning of the question mark.
If you don't escape it, your expression:
^thankYou.sjs?donate_path$
Would match
thankYou.sjsdonate_path
or
thankYou.sjdonate_path
Not to mention the special meaning of dot.
So I guess something like this should work:
thankYou\.sjs\?donate_path
Furthermore if it's possible that the donate_path is not the first in the query string you can use this:
thankYou\.sjs\?([^&]*&)*donate_path
Just the string itself will work. If you want only this string, just use the start/end of string zero-width assertions:
^thankYou\.sjs\?donate_path$