regex_error. What's wrong with my regex - c++

I'm getting regex_error for some reason. I also tried it the regular way of using escape characters (this method eliminates the need for escape sequences in c++ 11 by putting R"(something)" )
By the way if anyone was wondering, they are for recognizing lines in xml
When I use a web based regex tester it works fine.
string sstart = R"(\w*+(> ? +[^\\])++>)";
string send = R"(.*<\\\w\w[^m-o][^_]++)";
string sdata = R"([^>]++>[^ ]++)";
regex endtag(send);
regex taganddata(sdata);
regex starttag(sstart);

Syntax of you regular expressions is incorrect because of '++' part.
.+ matches one or more occurrences. But what do you try to match with .++ ?

Related

GAS Regex, Can someone turn make this regex to work in App Script?

From this page,(What is a good regular expression to match a URL?)
we can use regular expression to match a lot of URL,( it works as testing in regex website. somehow it is not working in GAS(Google App Script ) since using it as
var rx = 'https?:\/\/(www\.)?[-a-zA-Z0-9#:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()#:%_\+.~#?&\/\/=]*)';
regex= string.match(rx)
Logger.log(regex)
It always return null as
Info null
However this regex works on this page https://regexr.com. How can we make it works with GAS?
How can we match something like this in GAS?
https://notifications.example.com/f/g/FB-FnExAZJUxP7fPZCGR4kW9FodXg0X1GBR4wZ0GUaAV0DgL3xUT1K2gBsxnQVcGbzPcydEWIwOgDQ-GiVzMERg5FPGm1Ek6YWnAyElHsz5uqJe5wYYtgQbGuQmW5WxF6E8bu9CfRtBEJ7AWDxWSwfOu__Ahwrwsnw
Your code is not working because it is not using a regex. It is simply matching one text string against another.
To make it work, use a regex literal, like this:
const rx = /https?:\/\/(www\.)?[-a-zA-Z0-9#:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()#:%_\+.~#?&\/\/=]*)/i;
If you need to use a text string literal for some reason, double escape the text string using \\ in place of \, and apply the RegExp() constructor to make a regex of it.

matching beginning of string and excluding end of string in regex

I have some strings like the following:
abc4back
abc4backpre
abc4front
abc4frontpre
abc3side
abc3sidepre
xyz4over
xyz4overpre
and I want to get those only with the "abc4" but without the "pre". So far, my regex is:
abc4.*(?!pre).
But, when I ran this, I got the error:
error parsing regexp: invalid or unsupported Perl syntax: `(?!` .
I now know that this is because lookaheads are not supported in go.
But, I cannot figure out what expression I should use instead of ?!. Does anyone know what will work?
you can do this by multi negated character as
^abc4(?:.*(?:[^p].{2}|p[^r].{1}|pr[^e])|.{0,2})$
Regex Demo

Does mongo regex query have character limit, if the regex search string is more than that limit it throws error

I am seeing mongo regex query not returning result when the regex searched string is very big, instead its throwing error. I have a scenario where I append lot of names to do a regex and thus my regex search string goes beyond 40000 characters.
eg:
db.getCollection('collection').find(
{"name":{"$regex" :"name1 | name2 | name3", "$options":"-i"}}
)
Can you explain why you are doing this?
The idea of a regex is to create a expression with which you match (multiple) value(s).
example expression:
name\d+
will match on all "namex" vales where x is a decimal.
The idea will be to create a single expression to fullfill your query requirement.
When you want to match on multiple string values you can use $and operator
Yes, mongoDB regex has character limit, originates from perl regex limit.
Because "MongoDB uses Perl compatible regular expressions (i.e. “PCRE” ) version 8.41 with UTF-8 support."MongoDB v3.2
You can see the limitation is 32764 characters:MongoDB add assert of regular expression length
I recently met this issue, and the solution was to use $in query operator instead. $in does not have characters limit. This suits my problem, since it was exact match rather than pattern matching in such long input case.

How do I craft a regular expression to exclude strings with parentheses

I have the following SDDL:
O:BAG:BAD:(A;;CCDCLCSWRP;;;BA)(A;;CCDCSW;;;WD)(A;;CCDCLCSWRP;;;S-1-5-32-562)(A;;CCDCLCSWRP;;;LU)(A;;CCLCRP;;;S-1-5-21-4217728705-3687557540-3107027809-1003)
Unfortunately I keep getting this:
(A;;CCDCLCSWRP;;;BA)(A;;CCDCSW;;;WD)
And what I want is just (A;;CCDCSW;;;WD).
My regex is: (\(A;.+;WD\)) : find "(A;" some characters ending in ";WD)"
I've tried making the match lazy and I've tried excluding the ")(" pair of characters based on a search of the stackoverflow regex tag looking for examples where others have answered similar questions.
I'm really confused why the exclusion of the parens isn't working:
(\(A;.+[^\(\)]*.+;WD\)) : find "(A;" followed by some characters where none of them are ")('' followed by other characters ending in ";WD)"
And this was my guess at using negative look around:
(\(A;.+^((?!\)\().).+;WD\))
which didn't match anything.
I'm also doing this in PowerShell v3.0 with the following code:
$RegExPattern = [regex]"(\($ACE_Type;.*;$ACE_SID\))+?"
if ($SDDL -match $RegExPattern) {
$MatchingACE = $Matches[0]
Where in this instance $ACE_Type = "A" and $ACE_SID = "WD".
You almost had the solution with your second regex pattern. The problem was that you included too many . wildcards. This should be all you need:
A;[^()]+;WD
And of course if you just want to capture the string in between A; and ;WD:
A;([^()]+);WD
Then just replace with \1.
I simplified this a lot and then added lookarounds so that you only matched the intended string (in between A;...;WD). This looks behind for A;, then matches 1+ non-parenthesis characters, while looking ahead for ;WD.
(?<=A;)[^()]+(?=;WD)
Regex101

mongodb regular expressions matching

i am having these kind of strings
"abc?ref1=app";
"abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"
where xxxxxxxxxxxxxxx is some string...
i want to write regular expression which should only match "abc?ref1=app" types of strings and should not match any other string like "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx" ..i mean it should only and only match "abc?ref1=app" type of strings...
i have written some thing like this /abc\?ref1=app/ ..but this will also match "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"
please tell me how to write regular expression which will only match "abc\?ref1=app"
You do not even need regex here, since mongoDB uses lexographical comparison
a simple
{ "myStr" : { $lte : "abc?ref1=app" }
where myStr is your db key
will work
a string like abc?ref1=app&xyz would be counted as greater than your query.
Add an end-of-line ($) token
abc\?ref1=app$